Shortcuts
I switched over to CachyOS the other day to try it out, as it’s been getting a lot of hype and I wanted to see if it lived up to it. So far? Yeah, it’s pretty good! For something Arch based, it has a nice installer, and everything does seem to be a bit snappier (is it some of the additional tweaks? The packages compiled for x86-64-v3? Just be the placebo effect?).
But that aside, as I was getting my normal things installed again, I figured it was a good time to blog about shortcuts. In this case, application shortcuts, or in Linux parlance, .desktop files.
I have a few things that I use where I launch the applications with modified command arguments. For example, Signal Desktop. If I just install it from using pacman (sudo pacman -S signal-desktop) and then launch it, it doesn’t show me a tray icon, which I like to have. I know if I launch it with the --use-tray-icon argument, it will show it.
Another thing is Chromium-based browsers. Occasionally I have need to use them, so I have Vivaldi installed. I like to scroll by clicking my mouse wheel and moving the mouse, which Firefox does out-of-box, but Chromium browsers don’t. That said, if you launch them with the --enable-blink-features=MiddleClickAutoscroll argument they will.
Now, this is one thing that annoys me about Linux package management. If I just modify the .desktop files for those two, sure it will work, but the next time either of those packages update, the package manager will clobber my changes, which sucks.
I could duplicate the .desktop files, given them different file names and different display names, but then I have to remember to pick the right one, and that also is kind of awkward.
So, my solution is to have a script run after the packager manager does (in Arch and Arch-based distros, I could accomplish this with a Pacman Hook script specific to those packages, but this works for any distro). I generally alias uwu to chain together my update commands, so I wrote a bash script called desktop-cleanup.sh, stuck it in ~/bin. and set my update command to alias uwu="pacman -Syu && sudo flatpak update && ~/bin/desktop-cleanup.sh" (there’s more stuff than this in there, but that’s the basic idea).
Now, whenever I do system updates, the following script runs, which checks the to see if the .desktop files contain the default Exec strings, and if so, re-writes them in-place to add in the arguments I want. There are probably better ways to do this, but it works for me. I also have some messages in so I know if something updated, or if no changes were needed (and if there are errors, they’ll display and because I chained with &&, which only runs the next command if the previous one executed successfully, the success echos won’t fire and the “No changes made.” messages appears if neither did anything).
#! /bin/bash
if grep -q 'Exec=signal-desktop -- %u' /usr/share/applications/signal-desktop.desktop; then
sudo sed -i -e 's/Exec=signal-desktop -- %u/Exec=signal-desktop --use-tray-icon -- %u/g' /usr/share/applications/signal-desktop.desktop && echo "Stock Signal desktop file updated with tray argument." && nothing=false
fi
if grep -q 'vivaldi-stable %U' /usr/share/applications/vivaldi-stable.desktop ; then
sudo sed -i -e 's/vivaldi-stable %U/vivaldi-stable --enable-blink-features=MiddleClickAutoscroll %U/g' /usr/share/applications/vivaldi-stable.desktop && echo "Stock Vivaldi desktop file updated with scroll argument.." && nothing=false
fi
if [ -z $nothing ]; then
echo "No changes made."
fi
To briefly explain, the if lines grep the .desktop file for the bit that I want to change, in this case, the default Exec(utable) and arguments. If the default I expect isn’t there, then it just skips making changes, otherwise it uses sed to to an in-place edit of the file using a regular expression to replace the stock bit with the same command, but with the argument I want inserted into it. Then it echo’s out a message to tell me it’s done something, and sets the variable nothing to false. Then this repeats for the second .desktop.
Finally, if neither has run, the variable nothing isn’t set, so this if statement will echo out “No changes made” (again, this will also happen if one or both try to update but error out, for example if there’s a permissions problem), otherwise if either of the commands have actually made changes at set nothing, then it will just skip this.
Again, there are probably better ways to do this, but I bodged this together a while back and it continues to work very nicely for me.