Skip to content

Instantly share code, notes, and snippets.

@pythoninthegrass
Last active May 12, 2023 06:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pythoninthegrass/106bef335269d5bea0becb0ffa80f2b5 to your computer and use it in GitHub Desktop.
Save pythoninthegrass/106bef335269d5bea0becb0ffa80f2b5 to your computer and use it in GitHub Desktop.
flatpak shim until they're added to path as expected
#!/usr/bin/env zsh
# SOURCES:
# https://github.com/magical-heyrovsky
# https://github.com/flatpak/flatpak/issues/994#issuecomment-1484158855
# https://apple.stackexchange.com/questions/296477/my-command-line-says-complete13-command-not-found-compdef
# https://unix.stackexchange.com/questions/353076/how-to-indent-an-heredoc-inside-an-heredoc-the-right-way
# * leading tabs: indent here-document (heredoc)
# * spaces: indent code within heredoc
if [[ $# -eq 0 ]]; then
cat <<- 'DESCRIPTION'
SETUP
Place in path (e.g., /usr/local/bin/fp) and make executable (chmod +x fp).
USAGE
fp <app>
DESCRIPTION
fi
# fp auto-completion
() {
# list of each flatpak app name in lowercase ("Brave Browser" == "brave")
local FLATPAK_APPS=$(flatpak list --app | cut -f1 | awk '{print tolower($1)}')
autoload -Uz bashcompinit && bashcompinit
autoload -Uz compinit && compinit
complete -W $FLATPAK_APPS fp
}
# run flatpak apps from cli (e.g., "fp okular")
function fp() {
app=$(flatpak list --app | cut -f2 | awk -v app="$1" '(tolower($NF) ~ tolower(app))')
# abort if the app name was not entered
test -z $1 && printf "\nINSTALLED APPS\n$app\n" && return
# remove app name from "$@" array
shift 1
# run the flatpak app async (subshell in background) and don't show any stdout and stderr
( flatpak run "$app" "$@" &> /dev/null & )
}
# launch main function with all arguments
fp "$@"
@pythoninthegrass
Copy link
Author

This is mostly necessary as I didn't want to add an alias to ~/.bashrc or ~/.bash_aliases and don't want to use zsh (bash + starship ftw)

Added to /usr/local/libexec on Fedora. /usr/local/bin works too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment