-
-
Save seven1m/e2973274520b25db8f7a7d9155cc8566 to your computer and use it in GitHub Desktop.
| #!/usr/bin/env ruby | |
| # https://mpov.timmorgan.org/clipboard-history-in-sway-window-manager/ | |
| require 'json' | |
| STORE = "#{ENV['HOME']}/.clipboard-history" | |
| LIMIT = 100 | |
| unless File.exist?(STORE) | |
| File.open(STORE, 'w') { |f| f.write('[]') } | |
| end | |
| puts 'read clips' | |
| clips = JSON.load(File.read(STORE)) | |
| if ARGV[0] == 'menu' | |
| puts 'show menu' | |
| sel = nil | |
| IO.popen("dmenu -p 'select a paste'", 'r+') do |io| | |
| io.write(clips.map(&:to_json).join("\n")) | |
| io.close_write | |
| sel = io.read | |
| end | |
| exit if sel.empty? | |
| IO.popen('wl-copy --type text/plain', 'w') { |io| io.write(JSON.parse(sel)) } | |
| else | |
| loop do | |
| clip = `wl-paste -n` | |
| if !clip.strip.empty? && clip != clips.first | |
| puts 'add clip' | |
| clips = ([clip] + clips).uniq[0...LIMIT] | |
| File.open(STORE, 'w') do |file| | |
| file.puts(JSON.pretty_generate(clips)) | |
| end | |
| end | |
| sleep 5 | |
| end | |
| end |
Thanks!
It works but every 5 seconds sway resize the current windows.
If I resolve the issue I'd like to use a terminal+fzf instead of dmenu, something like this
EDIT
The issue was for an old version of wl-clipboard!
Hi! @seven1m, I wanted to contact you for some time regarding your blog post you've linked: wl-clipboard 2.0 has introduced the --watch mode, which means it will notify you when the selection changes instead of you having to poll for it every few seconds.
See the man page, bugaevc/wl-clipboard#39 (comment) and bugaevc/wl-clipboard#59 for more info & discussion.
Please update your script & add an update to your blog post (or even write a new one). I'm trying to get everyone off of polling the clipboard to using the --watch mode 😄
Awesome! I'll see about getting this script updated!
Sorry about that. The script assumes there is something in the file I suppose. This should fix it: