Skip to content

Instantly share code, notes, and snippets.

@thingsiplay
Last active April 11, 2024 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thingsiplay/7996eac993fc4019993076445d8911b7 to your computer and use it in GitHub Desktop.
Save thingsiplay/7996eac993fc4019993076445d8911b7 to your computer and use it in GitHub Desktop.
Run Flatpak apps by search filter or through fuzzy finder menu
#!/usr/bin/env bash
# Show info and run flatpak apps with fzf
# flatapp [arguments]
flatpak_preview() {
app="$(echo "${1}" | awk -F'\t' '{print $2}')"
flatpak info "${app}"
}
export -f flatpak_preview
app="$(
flatpak list --app --columns=name,application |
fzf --preview 'flatpak_preview {}' \
--reverse \
--cycle \
--bind change:first \
--bind esc:cancel+clear-selection \
--height=100% \
--border=none \
--prompt='$ flatpak run ' \
--no-separator |
awk -F'\t' '{print $2}'
)"
if [ -z "${app}" ]; then
exit 1
fi
echo "flatpak run" "${app}" "${@}" >&2
flatpak run "${app}" "${@}"
#!/usr/bin/env bash
# Run a Flatpak app by search filter
#
# Search in application name and id and execute the matching entry.
# If multiple entries matches, print the ids instead.
#
# First argument is name of app to search. If it's lowercase only,
# then a simple case independent string search is done. If any
# special characters or uppercase is present, then search turns
# into case dependent extended regular expression.
#
# Second argument and all remaining arguments are added as
# additional argument to the called application.
#
# flatrun freetube
# flatrun 'com.+Studio' --help
if [ "${#}" -eq 0 ]; then
flatpak list --app --columns=name,application
else
name="${1}"
shift
if [[ "${name}" =~ ^[a-z]$ ]]; then
options='-i -F'
else
options='--no-ignore-case -E'
fi
app="$(
flatpak list --app --columns=name,application |
grep ${options} "${name}" - |
awk -F'\t' '{print $2}'
)"
if [ -z "${app}" ]; then
exit 1
elif [[ "$(echo "${app}" | wc -l)" -gt 1 ]]; then
echo "${app}"
else
echo "flatpak run" "${app}" "${@}" >&2
flatpak run "${app}" "${@}"
fi
fi
#!/usr/bin/env bash
# Search Flatpak repository and display apps with fzf for install or uninstall.
# flatsearch tube
if [ "${#}" -eq 0 ]; then
echo "Search term required." >&2
exit 1
fi
flatpak_preview() {
local app
app="$(echo "${1}" | awk -F'\t' '{print $3}')"
flatpak info "${app}" 2>/dev/null || echo "${1}" | sed 's/\t\t*/\n/g'
}
export -f flatpak_preview
app="$(
flatpak search --columns=all "${@}" |
fzf --preview 'flatpak_preview {}' \
--reverse \
--cycle \
--bind change:first \
--bind esc:cancel+clear-selection \
--height=100% \
--border=none \
--prompt='$ flatpak install ' \
--no-separator |
awk -F'\t' '{print $3}'
)"
if [ -z "${app}" ]; then
exit 1
fi
if flatpak info "${app}" >/dev/null 2>&1; then
flatpak uninstall "${app}"
else
flatpak install "${app}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment