Clipboard menu - bakkeby/dusk GitHub Wiki
The clipboard menu has been one of those surprise productivity boost tools for me.
The idea is pretty simple:
- save recurring commands or command fragments for future reference and
- copy those to the clipboard as and when needed
What to store in this clipboard and how to use it depends very much on what you do on a day to day basis with your computer.
The main limitation here is that multi-line text can't be stored.
An example demonstration launching the script.
The above lists up to the first 20 items stored in the clipboard. Here the second item is selected which holds a command to sort logs by time across multiple hosts.
It is not important for you to understand what this command does, but the gist of it is that I often need to grep for something across multiple log files and I could have output along these lines:
host-01.service_20250305_14.gz:03/05-14:44:07.421 ERROR To catch the bugger we need juice
host-01.service_20250305_14.gz:03/05-14:22:01.933 ERROR Belong to the competition or SIGHUP
host-02.service_20250305_14.gz:03/05-14:13:12.113 ERROR Your marbles have been permanently lost
host-03.service_20250305_14.gz:03/05-14:05:01.556 ERROR All culprits lead to failure
host-03.service_20250305_14.gz:03/05-14:16:14.924 ERROR Base 64 encoding error exception
host-04.service_20250305_14.gz:03/05-14:55:17.337 ERROR US ASCII charset not found
host-04.service_20250305_14.gz:03/05-14:21:08.181 ERROR Are all humans tasty?
Sometimes I need to sort the output based on time. Getting rid of the file and sorting is a simple solution, but then I can't tell what log file a particular log line came from should I need to have a closer look.
Having found an ideal solution to this particular issue I stored the command in the clipboard menu for future reference.
Pressing enter opens the cached command so that I can inspect it:
and pressing enter again copies the command to the clipboard so that I can paste it into the terminal of choice:
| sort --field-separator=":" -k 2
A visual clue indicating what has happened pops up as a notification:
The script has been written in a way that allows for menu items to be added, copied to the clipboard, updated and removed:
- typing out a new description allows you to cache (add) a new command
- selecting an existing item and pressing enter will copy the details to the clipboard
- selecting an existing item and changing it in some way will update it
- selecting an existing item and deleting all the text will remove it
The menu items are cached in a clipboard.dat
file stored in the same directory as the shell script.
Dependencies:
- dmenu
sed
notify-send
To set this up you will need:
- clipboard_menu.sh
- a keybinding set up e.g. via dusk or sxhkd
Example sxhkd keybinding:
super + ctrl + apostrophe
~/bin/clipboard_menu.sh
Example dusk keybinding:
{ KeyPress, Super|Ctrl, XK_apostrophe, spawn, CMD("~/bin/clipboard_menu.sh") }, // spawn clipboard menu
Tip: a clipboard solution like this can be particularly useful for commands / one-liners that you may need to take with you when connecting to remote servers.
There is also an experimental version that embeds into the current window and is specifically intended for terminals.
This variant piggy-backs on the commands cached in clipboard.dat
, but does not allow for new items to be added or for existing items to be updated.
Instead as soon as an item is selected the associated command is pasted straight into the terminal. Use with care.
Dependencies:
To set this up you will need:
- clipboard_terminal_menu.sh
- a keybinding set up e.g. via dusk or sxhkd
Example sxhkd keybinding:
super + alt + apostrophe
~/bin/clipboard_terminal_menu.sh
Example dusk keybinding:
{ KeyPress, Super|Alt, XK_apostrophe, spawn, CMD("~/bin/clipboard_terminal_menu.sh") }, // spawn clipboard menu
Back to Other scripts and life hacks.