diff options
-rw-r--r-- | README.md | 18 | ||||
-rwxr-xr-x | lclipd.lua | 26 |
2 files changed, 39 insertions, 5 deletions
@@ -54,10 +54,24 @@ fzf_lclipd() { fi } zle -N fzf_lclipd -bindkey '' fzf_lclipd +bindkey '^O' fzf_lclipd ``` You can also put the db on a network share and then have different instanecs on different hosts use the same common db, effectively sharing your clipboard between different devices on the same subnet.</br> + +You can run lclipd as a user service. The author uses this for runit:</br> +```sh +#!/bin/sh +exec \ + env \ + XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR}" \ + XAUTHORITY="${XAUTHORITY}" \ + DISPLAY=:0 \ + /usr/bin/lua5.3 \ + /home/devi/devi/lclip.git/in_memory/lclipd.lua \ + > /dev/null 2>&1 +``` + ## Options ``` @@ -66,6 +80,7 @@ Usage: ./lclipd.lua [-h] [-s <hist_size>] [-e <detect_secrets_exe>] [-c <custom_clip_command>] [--x_clip_cmd <x_clip_cmd>] [--wayland_clip_cmd <wayland_clip_cmd>] [--tmux_clip_cmd <tmux_clip_cmd>] [--db_path <db_path>] + [--sql_file <sql_file>] Options: -h, --help Show this help message and exit. @@ -92,6 +107,7 @@ Options: --tmux_clip_cmd <tmux_clip_cmd> the command used to get the tmux paste-buffer content (default: tmux show-buffer) --db_path <db_path> path to the db location,currently :memory: and ''(empty) is not supported (default: /dev/shm/lclipd) + --sql_file <sql_file> path to the file containing a sql file that will be executed about lclip starting every time (default: ) ``` ## Supported OSes @@ -119,6 +119,9 @@ parser:option("--tmux_clip_cmd", parser:option("--db_path", "path to the db location,currently :memory: and ''(empty) is not supported", "/dev/shm/lclipd") +parser:option("--sql_file", + "path to the file containing a sql file that will be executed about lclip starting every time", + "") --- Log the given string to syslog with the given priority. -- @param log_str the string passed to the logging facility @@ -226,17 +229,17 @@ local function detect_secrets(clipboard_content, args) local pid, errmsg = unistd.fork() if pid == nil then -- error - unistd.closr(pipe_read) - unistd.closr(pipe_write) + unistd.close(pipe_read) + unistd.close(pipe_write) log_to_syslog("could not fork", posix_syslog.LOG_CRIT) log_to_syslog(errmsg, posix_syslog.LOG_CRIT) lclip_exit(1) elseif pid == 0 then -- child unistd.close(pipe_read) - -- we need to use a random string that changes every time for + -- we need to use a random string that changes every time for -- the heredoc name so that we dont run the risk of having the name -- of the heredoc appear in the clipboard content. - -- we need to change the name every time to not end up with a + -- we need to change the name every time to not end up with a -- heredoc-ception scenario. local random_str = get_random_str(15) local cmd = string.format(detect_secrets_cmd, @@ -506,6 +509,19 @@ local function clipboard_writer(args, sqlite_handle) end end +local function add_triggers_from_file(args, sqlite_handle) + local trigger_file = io.open(args["sql_file"], "r") + if not trigger_file then return end + local content = trigger_file:read("*a") + trigger_file:close() + + local return_code = sqlite_handle:exec(content) + if return_code ~= sqlite3.OK then + log_to_syslog("error executing sql file:", posix_syslog.LOG_WARNING) + log_to_syslog(tostring(return_code), posix_syslog.LOG_WARNING) + end +end + --- The clipboard's main loop -- @param args the cli args local function loop(args) @@ -530,6 +546,8 @@ local function loop(args) lclip_exit(1) end + add_triggers_from_file(args, sqlite_handle) + -- run the server process run_server(args, sqlite_handle) |