#!/usr/bin/env lua5.3 -- needs xsel, clipnotify -- needs luaposix, luarocks-5.3 install --local luaposix -- cat .clip_history | dmenu -l 10 | xsel -ib 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 string = require("string") -- local signal = require("posix.signal") -- signal.signal(signal.SIGINT, function(signum) os.exit(128 + signum) end) -- FIXME-clip history size is not being used local function loop() local clip_hist_size = 100 local clip_hist = "/home/devi/.clip_history" local matched = false while true do local wait_for_event = io.popen("clipnotify") local handle = io.popen("xsel -ob") local last_clip_entry = handle:read("*a") local hist_file = io.open(clip_hist, "a+") for line in hist_file:lines() do if (string.sub(line, 0, string.len(line)) == last_clip_entry) then matched = true end end if matched ~= true then hist_file:write(last_clip_entry .. "\n") end matched = false hist_file:close() wait_for_event:close() handle:close() end end loop()