For example VS Code usually allows you to run a command through terminal like
code ~/src/my-project
but when installed via flatpak I must do
flatpak run com.visualstudio.code ~/src/my-project
I was able to shorten it up by putting an alias in my bashrc file like this
alias code='flatpak run com.visualstudio.code'
That’s okay for one or two programs, but now that I’m running silverblue I’m wondering if there is a better way to do this. I was wondering if it’s possible for a flatpak to export/provide this alias to the host so manual intervention isn’t necessary when installing. Much like in JavaScript how you can export a function as a third part in your module and someone (the host in this case) would know based on some sort of standard that it should include the alias
To a large degree, but not entirely the goal. I remember running OpenSuse way back and I was developing in Java at the time. If you had multiple Java SDKs, you could switch which javac binary would be executed pretty easy using update-alternatives if I remember correctly. I was thinking something along those lines to manage large amounts of installed software through flatpaks.
Say I remove org.mozilla.Firefox with flatpak. I may have added an alias firefox that pointed to that flatpak a year ago, and now have an alias that points to a nonexistent flatpak. I then install org.mozilla.firefox (one from flathub has different case). Well unbeknownst to me, as a user I may try to run firefox https://duckduckgo.com. It would be confusing because bash autocomplete would work, yet the command would not run. Sure I would realize at that point pretty quickly from the error that it is somehow pointing at the old firefox and I could hunt it down. But as more programs are installed in that bashrc file it starts looking “messy”.
I didn’t actually think of flatpak potentially having a feature itself, was thinking more along the lines of a wrapper that would have hooks anytime flatpak installs/removes a flatpak it would automatically provide/remove the symlinks to relevant binaries, assuming it’s not an alternative, at which point would ask which one to use.
When I created this question I didn’t remember what update-alternatives was called though. I may make a little program to do what I’m thinking now that I remember that’s a thing.
The following function “cre-flp-aliases” creates aliases for every installed Flatpak application at runtime.
If you called the function in .bashrc an alias is available.
Example of an alias: alias flatseal=‘flatpak run com.github.tchx84.Flatseal &’
cre-flp-aliases ()
{
declare strAlias;
declare strFlatpakPath;
strFlatpakPath="/var/lib/flatpak/app/";
strAlias=$(find "${strFlatpakPath}"* -maxdepth 0 -type d | awk -F "/" '{ print$6 }' | awk -F "." '{print "alias "tolower($NF)"=?flatpak run "$0 " &?" }' | tr "?" "'");
for flpAlias in "${strAlias[@]}";
do
eval "$flpAlias";
done;
}
...