diff options
Diffstat (limited to 'lclipd.lua')
-rwxr-xr-x | lclipd.lua | 92 |
1 files changed, 58 insertions, 34 deletions
@@ -6,6 +6,27 @@ -- luarocks-5.3 install --local lsqlite3 -- sqlite3 $(cat /tmp/lclipd_db_name) 'select content from lclipd;' | dmenu -l 10 | xsel -ib local string = require("string") + +local function default_luarocks_modules() + local luarocks_handle = io.popen("luarocks-5.3 path --bin") + local path_b = false + local cpath_b = false + for line in luarocks_handle:lines() do + local path = string.match(line, "LUA_PATH%s*=%s*('.+')") + local cpath = string.match(line, "LUA_CPATH%s*=%s*('.+')") + if path ~= nil then + package.path = package.path .. ";" .. string.sub(path, 2, -2) + end + if cpath ~= nil then + package.cpath = package.cpath .. ";" .. string.sub(cpath, 2, -2) + end + end + + if path_b then os.exit(1) end + if cpath_b then os.exit(1) end +end +default_luarocks_modules() + local signal = require("posix.signal") local argparse = require("argparse") local sys_stat = require("posix.sys.stat") @@ -21,8 +42,8 @@ create table if not exists lclipd ( ); ]=] -local sql_trigger = [=[ -create trigger if not exists hist_prune before insert on lclipd +local sql_dupe_trigger = [=[ +create trigger if not exists hist_dupe_prune before insert on lclipd begin delete from lclipd where id = ( @@ -31,8 +52,20 @@ begin where (select count(id) from lclipd where content == o.content) > 1 order by id limit 1 - ) - and ( + ); +end; +]=] + +local sql_old_reap_trigger = [=[ +create trigger if not exists hist_old_reap before insert on lclipd +begin + delete from lclipd + where id = ( + select id from lclipd + order by timeAdded + asc + limit 20 + ) and ( select count(id) from lclipd ) >= XXX; @@ -50,25 +83,6 @@ local db_file_name = "/tmp/lclipd_db_name" local function remove_pid_file() os.remove(pid_file) end --- Adds LUA_PATH and LUA_CPATH to the current interpreters path. -local function default_luarocks_modules() - local luarocks_handle = io.popen("luarocks-5.3 path --bin") - local path_b = false - local cpath_b = false - for line in luarocks_handle:lines() do - local path = string.match(line, "LUA_PATH%s*=%s*('.+')") - local cpath = string.match(line, "LUA_CPATH%s*=%s*('.+')") - if path ~= nil then - package.path = package.path .. ";" .. string.sub(path, 2, -2) - end - if cpath ~= nil then - package.cpath = package.cpath .. ";" .. string.sub(cpath, 2, -2) - end - end - - if path_b then os.exit(1) end - if cpath_b then os.exit(1) end -end -default_luarocks_modules() local function lclip_exit(n) os.exit(n) @@ -124,16 +138,16 @@ local function get_clipboard_content() handle_w:flush() local last_clip_entry_w = handle_w:read("*a") - local _, handle_p = pcall(io.popen, "pyclip paste") - handle_p:flush() - local last_clip_entry_p = handle_p:read("*a") + -- local _, handle_p = pcall(io.popen, "pyclip paste") + -- handle_p:flush() + -- local last_clip_entry_p = handle_p:read("*a") - if last_clip_entry_p ~= "" then - return last_clip_entry_p + -- if last_clip_entry_p ~= "" then + -- return last_clip_entry_p + if last_clip_entry_x ~= "" then + return last_clip_entry_x elseif last_clip_entry_w ~= "" then return last_clip_entry_w - elseif last_clip_entry_x ~= "" then - return last_clip_entry_x end end @@ -174,12 +188,22 @@ local function loop(clip_hist_size) lclip_exit(1) end - -- add the trigger - sql_trigger = sql_trigger:gsub("XXX", clip_hist_size) - return_code = sqlite_handle:exec(sql_trigger) + -- add the de-dupe trigger + return_code = sqlite_handle:exec(sql_dupe_trigger) + if return_code ~= sqlite3.OK then + log_to_syslog(tostring(return_code), posix_syslog.LOG_CRIT) + log_to_syslog("could not add dupe trigger to table", + posix_syslog.LOG_CRIT) + lclip_exit(1) + end + + -- add the old_reap trigger + sql_old_reap_trigger = sql_old_reap_trigger:gsub("XXX", clip_hist_size) + return_code = sqlite_handle:exec(sql_dupe_trigger) if return_code ~= sqlite3.OK then log_to_syslog(tostring(return_code), posix_syslog.LOG_CRIT) - log_to_syslog("could not add trigger to table", posix_syslog.LOG_CRIT) + log_to_syslog("could not add old_reap trigger to table", + posix_syslog.LOG_CRIT) lclip_exit(1) end |