Last active
November 23, 2024 19:16
-
-
Save ernstki/aae9e045369b48b517487c7e6694808d to your computer and use it in GitHub Desktop.
Create symlinks in your ~/bin for Flatpak apps, with sensible names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## | |
## Create symlinks for a list of flatpaks that you want to be able to run | |
## from the terminal without typing `flatpak run herp.derp.derp.App` every | |
## time. | |
## | |
## Author: Kevin Ernst <[email protected]> | |
## Date: Some time in November, 2024 | |
## License: ISC or WTFPL, at your option | |
## Homepage: https://gist.github.com/ernstki/aae9e045369b48b517487c7e6694808d | |
## | |
## Bugs: | |
## - instead of having to manually update the LINKS associative array and run | |
## this script, should just accept <flatpak> <link_name> as argumetns and | |
## then update a secondary data file in $XDG_WHATEVER_WHATEVER | |
## | |
## <rant> | |
## I get it, Flatpak apps are usually GUIs, and your desktop environment or | |
## your app store app is reponsible for installing those `.desktop` files | |
## wherever. | |
## | |
## But did _nobody_ who came up with this format ever want to run | |
## applications installed as flatpaks from the terminal, without having to | |
## type something like `flatpak run org.wezfurlong.wezterm` every time? | |
## | |
## Debian's "alternatives" system seems to have found a way of providing | |
## executables with the names that users expect them, in the the users' | |
## search path, and dealing with conflicts like `batcat` and `fdfind`. | |
## </rant> | |
## | |
set -u | |
TRACE=${TRACE:-} | |
(( TRACE )) && set -x | |
MYNAME=${BASH_SOURCE##*/} | |
declare -A LINKS | |
LINKS=( | |
[org.wezfurlong.wezterm]=wezterm | |
[io.elementary.calculator]=calc | |
) | |
(( TRACE )) && declare -p LINKS | |
# if we're run as a symlink | |
if [[ -L $BASH_SOURCE ]]; then | |
declare -A flatpaks # create an inverse index real quick | |
for fp in "${!LINKS[@]}"; do flatpaks[${LINKS[$fp]}]=$fp; done | |
(( TRACE )) && declare -p flatpaks | |
flatpak=${flatpaks[$MYNAME]} | |
( set -x; flatpak run $flatpak "$@" ) | |
else | |
pushd ~/bin >/dev/null | |
for flatpak in "${!LINKS[@]}"; do | |
link=${LINKS[$flatpak]} | |
if [[ -L ~/bin/$link ]]; then | |
echo "Link $flatpak → ~/bin/$link already exists." >&2; | |
continue | |
fi | |
echo "Linking $flatpak → ~/bin/$link…" >&2; | |
( set -x; ln -s $MYNAME $link ) | |
done | |
popd >/dev/null | |
echo "Done." >&2; | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# to use this, type `make -f zz_Makefile` | |
# because https://github.com/orgs/community/discussions/86555 | |
# | |
help: | |
@echo "Type 'make install' to edit the list of links, then install to your ~/bin directory." >&2; | |
install: flatpak-link edit | |
@if ! echo "$$PATH" | tr : \\n | grep -qF "$$HOME/bin"; then \ | |
echo "NOTE: Your ~/bin directory is not in the PATH. You may just need to" >&2; \ | |
echo " log out and back in (or '. ~/.{bash_,}profile') to fix this." >&2; \ | |
fi | |
install -m755 $< ~/bin | |
~/bin/$< | |
edit: flatpak-link | |
$${EDITOR:-nano} $< | |
# vim: ft=make |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment