This is my attemp to make a shortcut I regularly use more...flexible, so that it can be useful for more...copying.
Currently I copy a single string with xclip.
This is an attempt to make it functional in both Xorg, as it is now, as well as Wayland (without XWayland). At the same time I figured I can just as well split up the strings it is to copy from the functionality of actually performinng the copy operation, either with xclip or wl-clipboard depending on whether you are using Xorg or Wayland.
So this "program"/script/functionality is split into two files:
- a Config file named
copyStuff.conflocated at$HOME/.config/. This file contains everything that can be copied in a neat file. - The script, called
copyStuff.shwhich is a simpple bash script that performs the copy. This file shouold be copied to$HOME/.local/bin/. That way they don't get overridden because of something, and it makes the internal functioncpsavailable in terminal sessions.
I'm not going to package something this simple an installable archive or something of the sort. I'm not even going to upload it to the AUR. This is way to simple for something like that. Instead just:
- Download and copy the empty
copyStuff.conffile to$HOME/.config/so that the eventual path is$HOME/.config/copyStuff.conf. This way every user has his/her/its own list of things to copy. 2.1. For a local (user-only) installation, download and move thecopyStuff.shscript into your local user's$HOME/.local/bin/. I'm using Manjaro, but I suspect it'll be the same, or at least similar, on many other a distro. 2.2. For a global (system-wide) installation, download and copy thecopyStuff.shsomewhere that system-wide scripts are kept. On my system I use/usr/local/binfor this, so the complete path for me would be/usr/local/bin/copyStuff.sh. Yours might differ. The global installation is only for the script. The stuff (to use a technical word) to copy must still be defined per-user, as desribed below. - Add the full path
copyStuff.confto your~/.bashrcor~/.zshrcor whatever you use. Asssuming the script has been saved as$HOME/.config/copyStuff.confthe line to add it would be:
source $HOME/.local/bin/copyStuff.conf
Adjust the path accordingly if you did a global installation. I use ZSH, but the script is written in bash, and the shebang is for bash, so it should work for you as well. Adjust to your needs if neccesary.
Now simply source/reload your ~/.bashrc or ~/.zshrc file and:
source <~/.bashrc or ~/.zshrc>
...and you should be good to go. It should also work after a reboot, if that will be eaier. Or a simple relogin. And it should persist after a reboot/relogin.
There is also the option to create shortcuts to do the copying. (Yes, I do this, what can I say? It makes my life easier.) There are 3 pre-defined strings to copy in copyStuff.conf and 3 matching .desktop files to use as examples.
Simply copy the .desktop files into $HOME/.local/share/applications/:
cp copy-*.desktop $HOME/.local/share/applications/
Edit and change the as required, and update the .desktop file database:
update-desktop-database $HOME/.local/share/applications/
The shortcuts should now appear in you launcher, by default in the Utilities section.(At least that's my experience on KDE Plasma.)
Well, I don't belive in re-inventing the wheel, so I use some things that have beenn built before so why would I re-invent those or roll my own? So without further ado:
xclipif you use X11; orwl-clipboardif you use Wayland; andlibnotifyfor displaying the notification that the copy process was sucessfull.
To test if it's loaded, in a terminal emulator, simply do:
cps -h
...is easy. That's why I made this, after all. After Simply run cps <stringToCopy>. For example:
cps ok
This will copy whatever is defined as ok in the $HOME/.config/copyStuff.conf config file.