Skip to content

Instantly share code, notes, and snippets.

@uncomfyhalomacro
Last active November 27, 2021 03:06
Show Gist options
  • Save uncomfyhalomacro/4c1bff902b6c7083f9399d44ad923f3e to your computer and use it in GitHub Desktop.
Save uncomfyhalomacro/4c1bff902b6c7083f9399d44ad923f3e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Launcher for executables inside desktop files
shopt -s lastpipe
source ~/.bashrc
IFS=$'\n' read -r -d '' -a desktops <<< "$(find /usr/share/applications/ $HOME/.local/share/applications/ $HOME/.local/share/flatpak/exports/share/applications/ -name "*.desktop" 2> /dev/null)"
for i in "${desktops[@]}"; do echo "$(cat "${i}" | awk -F: '/^Name=/{sub(/^Name=/, ""); print; exit}')" ; done | fzf -e -i --prompt='launch: ' | read -r cmd
for i in "${desktops[@]}"
do
if grep -Fxq "Name=${cmd}" "${i}"
then
Exec="$(cat "${i}" | awk -F: '/^Exec=/{sub(/^Exec=/,""); print; exit}' | sed -E 's/%(U|F)//g')"
Terminalorno="$(cat "${i}" | awk '/^Terminal=/{sub(/^Terminal=/,""); print}')"
[ -z "${Exec}" ] && exit
if [ "${Terminalorno}" = "true" ]
then
riverctl spawn "source ~/.bashrc; ${1} ${Exec}"
else
riverctl spawn "source ~/.bashrc; ${Exec}"
fi
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment