aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2023-07-06 20:31:14 +0000
committerterminaldweller <devi@terminaldweller.com>2023-07-06 20:31:14 +0000
commitcf712c045391478c4030e0b8dc0276310d693e83 (patch)
tree6a3f78664c3a2b0210fe983db7bdb84757c892b6
parentfixed the heredoc erroneous error code handling, now properly escaping the he... (diff)
downloadlclip-in_memory.tar.gz
lclip-in_memory.zip
added a new option that allows running a sql file on startup, added a user service example for runit in the READMEin_memory
-rw-r--r--README.md18
-rwxr-xr-xlclipd.lua26
2 files changed, 39 insertions, 5 deletions
diff --git a/README.md b/README.md
index b11370c..d0d2f02 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/lclipd.lua b/lclipd.lua
index 502bdf9..3132bc4 100755
--- a/lclipd.lua
+++ b/lclipd.lua
@@ -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)