From 7a4b9bdaeb7cbba64a5fc06a4e7019b7a47cfffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20Mei=C3=9Felbach?= Date: Fri, 25 Oct 2019 23:51:06 +0200 Subject: Put helper function in actual functions and call them with a slim switch/case. Call binaries with the specified terminal startup command --- sway-launcher-desktop.sh | 58 +++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh index 461ca4d..729256f 100755 --- a/sway-launcher-desktop.sh +++ b/sway-launcher-desktop.sh @@ -8,8 +8,20 @@ set -o pipefail trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR IFS=$'\n\t' -if [[ "$1" == 'describe' ]]; then - shift +# Defaulting terminal to termite, but feel free to either change +# this or override with an environment variable in your sway config +# It would be good to move this to a config file eventually +TERMINAL_COMMAND="${TERMINAL_COMMAND:="termite -e"}" +GLYPH_COMMAND=" " +GLYPH_DESKTOP=" " +HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-history.txt" +DIRS=( + /usr/share/applications + "$HOME/.local/share/applications" + /usr/local/share/applications +) + +function describe() { if [[ $2 == 'command' ]]; then title=$1 readarray arr < <(whatis -l "$1" 2>/dev/null) @@ -21,18 +33,9 @@ if [[ "$1" == 'describe' ]]; then fi echo -e "\033[33m$title\033[0m" echo "${description:-No description}" - exit -fi +} -# Defaulting terminal to termite, but feel free to either change -# this or override with an environment variable in your sway config -# It would be good to move this to a config file eventually -TERMINAL_COMMAND="${TERMINAL_COMMAND:="termite -e"}" -GLYPH_COMMAND=" " -GLYPH_DESKTOP=" " - -if [[ "$1" == 'entries' ]]; then - shift +function entries() { awk -v pre="$GLYPH_DESKTOP" -F= ' BEGINFILE{application=0;block="";a=0} /^\[Desktop Entry\]/{block="entry"} @@ -61,12 +64,9 @@ if [[ "$1" == 'entries' ]]; then }' \ "$@" >"$FZFPIPE" + entries "$dir"/*.desktop >>"$FZFPIPE" done ) & @@ -187,10 +185,10 @@ readarray -d $'\034' -t PARAMS <<<${COMMAND_STR} # COMMAND_STR is "\034" case ${PARAMS[1]} in desktop) - command=$($0 generate-command "${PARAMS[0]}" "${PARAMS[3]}") + command=$(generate-command "${PARAMS[0]}" "${PARAMS[3]}") ;; command) - command="${PARAMS[0]}" + command="$TERMINAL_COMMAND ${PARAMS[0]}" ;; esac -- cgit v1.2.3