diff options
author | terminaldweller <thabogre@gmail.com> | 2022-01-27 07:14:16 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2022-01-27 07:14:16 +0000 |
commit | b6e3c49e63324eddd2e56fa7e918821e7a497d33 (patch) | |
tree | 632318e6576e8c8ffeee11c9bae7f7a65a27c181 /bin | |
parent | updates (diff) | |
download | scripts-b6e3c49e63324eddd2e56fa7e918821e7a497d33.tar.gz scripts-b6e3c49e63324eddd2e56fa7e918821e7a497d33.zip |
updates
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/clipd | 39 | ||||
-rwxr-xr-x | bin/extractor | 86 |
2 files changed, 84 insertions, 41 deletions
diff --git a/bin/clipd b/bin/clipd new file mode 100755 index 0000000..0c200c6 --- /dev/null +++ b/bin/clipd @@ -0,0 +1,39 @@ +#!/usr/bin/env lua5.3 + +-- needs xsel, clipnotify +-- needs luaposix, luarocks-5.3 install --local luaposix +-- cat .clip_history | dmenu -l 10 | xsel -ib +-- FIXME-all entries are copied with an extra new line +local clipd = {} +local string = require("string") +local signal = require("posix.signal") + +signal.signal(signal.SIGINT, function(signum) os.exit(128 + signum) end) + +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() +return clipd diff --git a/bin/extractor b/bin/extractor index c6dc4e7..4b56d1b 100755 --- a/bin/extractor +++ b/bin/extractor @@ -1,9 +1,10 @@ #!/usr/bin/env lua ---by Egor Skriptunoff here:https://stackoverflow.com/questions/23590304/finding-a-url-in-a-string-lua-pattern +-- by Egor Skriptunoff here:https://stackoverflow.com/questions/23590304/finding-a-url-in-a-string-lua-pattern local extractor = {} function extractor.getURLS(text_with_URLs) - local domains = [[.ac.ad.ae.aero.af.ag.ai.al.am.an.ao.aq.ar.arpa.as.asia.at.au + local domains = + [[.ac.ad.ae.aero.af.ag.ai.al.am.an.ao.aq.ar.arpa.as.asia.at.au .aw.ax.az.ba.bb.bd.be.bf.bg.bh.bi.biz.bj.bm.bn.bo.br.bs.bt.bv.bw.by.bz.ca .cat.cc.cd.cf.cg.ch.ci.ck.cl.cm.cn.co.com.coop.cr.cs.cu.cv.cx.cy.cz.dd.de .dj.dk.dm.do.dz.ec.edu.ee.eg.eh.er.es.et.eu.fi.firm.fj.fk.fm.fo.fr.fx.ga @@ -17,50 +18,53 @@ function extractor.getURLS(text_with_URLs) .to.tp.tr.travel.tt.tv.tw.tz.ua.ug.uk.um.us.uy.va.vc.ve.vg.vi.vn.vu.web.wf .ws.xxx.ye.yt.yu.za.zm.zr.zw]] - local tlds = {} + local tlds = {} - for tld in domains:gmatch'%w+' do - tlds[tld] = true - end - local function max4(a,b,c,d) return math.max(a+0, b+0, c+0, d+0) end - local protocols = {[''] = 0, ['http://'] = 0, ['https://'] = 0, ['ftp://'] = 0} - local finished = {} + for tld in domains:gmatch '%w+' do tlds[tld] = true end + local function max4(a, b, c, d) + return math.max(a + 0, b + 0, c + 0, d + 0) + end + local protocols = { + [''] = 0, + ['http://'] = 0, + ['https://'] = 0, + ['ftp://'] = 0 + } + local finished = {} - for pos_start, url, prot, subd, tld, colon, port, slash, path in - text_with_URLs:gmatch'()(([%w_.~!*:@&+$/?%%#-]-)(%w[-.%w]*%.)(%w+)(:?)(%d*)(/?)([%w_.~!*:@&+$/?%%#=-]*))' - do - if protocols[prot:lower()] == (1 - #slash) * #path and not subd:find'%W%W' - and (colon == '' or port ~= '' and port + 0 < 65536) - and (tlds[tld:lower()] or tld:find'^%d+$' and subd:find'^%d+%.%d+%.%d+%.$' - and max4(tld, subd:match'^(%d+)%.(%d+)%.(%d+)%.$') < 256) - then - finished[pos_start] = true - print(pos_start, url) - end - end + for pos_start, url, prot, subd, tld, colon, port, slash, path in + text_with_URLs:gmatch '()(([%w_.~!*:@&+$/?%%#-]-)(%w[-.%w]*%.)(%w+)(:?)(%d*)(/?)([%w_.~!*:@&+$/?%%#=-]*))' do + if protocols[prot:lower()] == (1 - #slash) * #path and + not subd:find '%W%W' and + (colon == '' or port ~= '' and port + 0 < 65536) and + (tlds[tld:lower()] or tld:find '^%d+$' and + subd:find '^%d+%.%d+%.%d+%.$' and + max4(tld, subd:match '^(%d+)%.(%d+)%.(%d+)%.$') < 256) then + finished[pos_start] = true + print(pos_start, url) + end + end - for pos_start, url, prot, dom, colon, port, slash, path in - text_with_URLs:gmatch'()((%f[%w]%a+://)(%w[-.%w]*)(:?)(%d*)(/?)([%w_.~!*:@&+$/?%%#=-]*))' - do - if not finished[pos_start] and not (dom..'.'):find'%W%W' - and protocols[prot:lower()] == (1 - #slash) * #path - and (colon == '' or port ~= '' and port + 0 < 65536) - then - print(pos_start, url) - end - end + for pos_start, url, prot, dom, colon, port, slash, path in + text_with_URLs:gmatch '()((%f[%w]%a+://)(%w[-.%w]*)(:?)(%d*)(/?)([%w_.~!*:@&+$/?%%#=-]*))' do + if not finished[pos_start] and not (dom .. '.'):find '%W%W' and + protocols[prot:lower()] == (1 - #slash) * #path and + (colon == '' or port ~= '' and port + 0 < 65536) then + print(pos_start, url) + end + end end -function main() - local input = io.read("*a") - for k,v in pairs(arg) do - if v == "--url" then - extractor.getURLS(input) - else - print("invalid args...") - os.exit(1) - end - end +local function main() + local input = io.read("*a") + for _, v in pairs(arg) do + if v == "--url" then + extractor.getURLS(input) + else + print("invalid args...") + os.exit(1) + end + end end main() |