From 9a57ba1ea2ee50acbb73a78a35e11594a659e07b Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Sun, 12 Feb 2023 22:09:02 +0330 Subject: wip --- lclipd.lua | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/lclipd.lua b/lclipd.lua index 18ff032..0d64656 100755 --- a/lclipd.lua +++ b/lclipd.lua @@ -10,6 +10,38 @@ local argparse = require("argparse") local sys_stat = require("posix.sys.stat") local unistd = require("posix.unistd") local posix_syslog = require("posix.syslog") +local sqlite3 = require("lsqlite3") + +local sql_create_table = [=[ +create table if not exists lclipd ( + id integer primary key autoincrement, + content text unique, + dateAdded integer, +); +]=] + +-- TODO +local sql_trigger = [=[ +create trigger t_bi_prune before insert on t +begin + delete from t + where ID = ( + select ID + from t as o + where (select count(ID) from t where GroupID == o.GroupID) > 1 + and Ack != 1 + order by ID + limit 1 + ) + and ( + select count(ID) + from t + ) >= 6; +]=] + +local sql_insert = [=[ +insert into lclipd (,%s,unixepoch()); +]=] --- Adds LUA_PATH and LUA_CPATH to the current interpreters path. local function default_luarocks_modules() @@ -79,7 +111,7 @@ local function check_clip_hist_perms(clip_hist) end end ---- Checks to make sure there the pid file for clipd does not exist. +--- Checks to make sure that the pid file for clipd does not exist. local function check_pid_file() local f = sys_stat.stat("/var/run/clipd.pid") if f ~= nil then @@ -103,6 +135,40 @@ end -- TODO- implement me local function remove_pid_file() end +--- Get the clipboard content from X or wayland. +local function get_clipboard() + local wait_for_event_x = io.popen("clipnotify") + local handle_x = io.popen("xsel -ob") + local last_clip_entry_x = handle_x:read("*a") + + local wait_for_event_w = io.popen("clipnotify") + local handle_w = io.popen("xsel -ob") + local last_clip_entry_w = handle_w:read("*a") + + if last_clip_entry_x ~= "" then + return last_clip_entry_x + else + return last_clip_entry_w + end +end + +--- Get the sqlite DB handle. +local function get_sqlite_handle() + local tmp_db_name = "/tmp/" .. + io.popen( + "tr -dc A-Za-z0-9