diff options
| -rwxr-xr-x | sway-launcher-desktop.sh | 79 | ||||
| -rw-r--r-- | tests/data/htop.desktop | 65 | ||||
| -rw-r--r-- | tests/data/minecraft-launcher.desktop | 10 | ||||
| -rw-r--r-- | tests/describe.bats | 2 | ||||
| -rw-r--r-- | tests/entries.bats | 14 |
5 files changed, 136 insertions, 34 deletions
diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh index 5d06a4b..ff41305 100755 --- a/sway-launcher-desktop.sh +++ b/sway-launcher-desktop.sh @@ -2,9 +2,15 @@ # terminal application launcher for sway, using fzf # Based on: https://gitlab.com/FlyingWombat/my-scripts/blob/master/sway-launcher # https://gist.github.com/Biont/40ef59652acf3673520c7a03c9f22d2a - shopt -s nullglob -if [[ "$1" == 'describe' ]]; then +set -uo pipefail +# shellcheck disable=SC2154 +trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR +IFS=$'\n\t' + +SUBCOMMAND=${1:-} + +if [[ -n $SUBCOMMAND ]] && [[ "$SUBCOMMAND" == 'describe' ]]; then shift if [[ $2 == 'command' ]]; then title=$1 @@ -20,6 +26,43 @@ if [[ "$1" == 'describe' ]]; then exit fi +GLYPH_COMMAND=" " +GLYPH_DESKTOP=" " + +if [[ -n $SUBCOMMAND ]] && [[ "$SUBCOMMAND" == 'entries' ]]; then + shift + awk -v pre="$GLYPH_DESKTOP" -F= ' + BEGINFILE{application=0;block="";a=0} + /^\[Desktop Entry\]/{block="entry"} + /^Type=Application/{application=1} + /^\[Desktop Action/{ + sub("^\\[Desktop Action ", ""); + sub("\\]$", ""); + block="action"; + a++; + actions[a,"key"]=$0 + } + /^Name=/{ + if(block=="action") { + actions[a,"name"]=$2; + } else { + name=$2 + } + } + ENDFILE{ + if (application){ + print FILENAME "\034desktop\034\033[33m" pre name "\033[0m"; + if (a>0) + for (i=1; i<=a; i++) + print FILENAME "\034desktop\034\033[33m" pre name "\033[0m (" actions[i, "name"] ")\034" actions[i, "key"] + } + }' \ + "$@" </dev/null + # the empty stdin is needed in case no *.desktop files + + exit 0 +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 @@ -33,9 +76,6 @@ DIRS=( /usr/local/share/applications ) -GLYPH_COMMAND=" " -GLYPH_DESKTOP=" " - touch "$HIST_FILE" readarray HIST_LINES <"$HIST_FILE" FZFPIPE=$(mktemp) @@ -49,34 +89,7 @@ trap 'rm "$FZFPIPE" "$PIDFILE"' EXIT INT ( for dir in "${DIRS[@]}"; do [[ -d "$dir" ]] || continue - awk -v pre="$GLYPH_DESKTOP" -F= ' - BEGINFILE{application=0;block="";a=0} - /^\[Desktop Entry\]/{block="entry"} - /^Type=Application/{application=1} - /^\[Desktop Action/{ - sub("^\\[Desktop Action ", ""); - sub("\\]$", ""); - block="action"; - a++; - actions[a,"key"]=$0 - } - /^Name=/{ - if(block=="action") { - actions[a,"name"]=$2; - } else { - name=$2 - } - } - ENDFILE{ - if (application){ - print FILENAME "\034desktop\034\033[33m" pre name "\033[0m"; - if (a>0) - for (i=1; i<=a; i++) - print FILENAME "\034desktop\034\033[33m" pre name "\033[0m (" actions[i, "name"] ")\034" actions[i, "key"] - } - }' \ - "$dir/"*.desktop </dev/null >>"$FZFPIPE" - # the empty stdin is needed in case no *.desktop files + "$0 entries $dir/*.desktop" >>"$FZFPIPE" done ) & diff --git a/tests/data/htop.desktop b/tests/data/htop.desktop new file mode 100644 index 0000000..13b71e7 --- /dev/null +++ b/tests/data/htop.desktop @@ -0,0 +1,65 @@ +[Desktop Entry] +Version=1.0 +Name=Htop +Type=Application +Comment=Show System Processes +Comment[ca]=Mostra els processos del sistema +Comment[de]=Systemprozesse anzeigen +Comment[en_GB]=Show System Processes +Comment[es]=Mostrar procesos del sistema +Comment[fi]=Katsele järjestelmän prosesseja +Comment[fr]=Affiche les processus système +Comment[gl]=Mostrar os procesos do sistema. +Comment[it]=Mostra processi di sistema +Comment[ko]=시스템 프로세스 보기 +Comment[nb]=Vis systemprosesser +Comment[nl]=Systeemprocessen tonen +Comment[nn]=Vis systemprosessar +Comment[pl]=Pokaż procesy systemowe +Comment[pt]=Mostrar os Processos do Sistema +Comment[pt_BR]=Mostra os processos do sistema +Comment[ru]=Просмотр списка процессов в системе +Comment[sk]=Zobraziť systémové procesy +Comment[sl]=Prikaz sistemskih opravil +Comment[sr]=Приказ системских процеса +Comment[sr@ijekavian]=Приказ системских процеса +Comment[sr@ijekavianlatin]=Prikaz sistemskih procesa +Comment[sr@latin]=Prikaz sistemskih procesa +Comment[sv]=Visa systemprocesser +Comment[tr]=Sistem Süreçlerini Göster +Comment[uk]=Перегляд системних процесів +Comment[zh_CN]=显示系统进程 +Comment[zh_TW]=顯示系統行程 +Terminal=true +Exec=htop +Icon=htop +Categories=ConsoleOnly;System; +GenericName=Process Viewer +GenericName[ca]=Visor de processos +GenericName[de]=Prozessanzeige +GenericName[en_GB]=Process Viewer +GenericName[es]=Visor de procesos +GenericName[fi]=Prosessikatselin +GenericName[fr]=Visualiseur de processus +GenericName[gl]=Visor de procesos +GenericName[it]=Visore dei processi +GenericName[ko]=프로세스 뷰어 +GenericName[nb]=Prosessviser +GenericName[nl]=Viewer van processen +GenericName[nn]=Prosessvisar +GenericName[pl]=Przeglądarka procesów +GenericName[pt]=Visualizador de Processos +GenericName[pt_BR]=Visualizador de processos +GenericName[ru]=Монитор процессов +GenericName[sk]=Prehliadač procesov +GenericName[sl]=Pregledovalnik opravil +GenericName[sr]=Приказивач процеса +GenericName[sr@ijekavian]=Приказивач процеса +GenericName[sr@ijekavianlatin]=Prikazivač procesa +GenericName[sr@latin]=Prikazivač procesa +GenericName[sv]=Processvisning +GenericName[tr]=Süreç Görüntüleyici +GenericName[uk]=Перегляд процесів +GenericName[zh_CN]=进程查看器 +GenericName[zh_TW]=行程檢視器 +Keywords=system;process;task diff --git a/tests/data/minecraft-launcher.desktop b/tests/data/minecraft-launcher.desktop new file mode 100644 index 0000000..e2c464c --- /dev/null +++ b/tests/data/minecraft-launcher.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Type=Application +Version=1.0 +Name=Minecraft Launcher +Comment=Official Minecraft Launcher +Exec=env GDK_BACKEND=x11 /opt/minecraft-launcher/minecraft-launcher +Path=/opt/minecraft-launcher/ +Icon=minecraft-launcher +Terminal=false +Categories=Game;Application; diff --git a/tests/describe.bats b/tests/describe.bats index 7d2f866..7f26184 100644 --- a/tests/describe.bats +++ b/tests/describe.bats @@ -1,5 +1,5 @@ @test "Name and description of firefox desktop file are properly extracted" { - run ../sway-launcher-desktop.sh describe data/firefox.desktop + run ../sway-launcher-desktop.sh describe data/firefox.desktop desktop [ "$status" -eq 0 ] [[ ${lines[0]} =~ "Firefox" ]] [[ ${lines[1]} =~ "Browse the World Wide Web" ]] diff --git a/tests/entries.bats b/tests/entries.bats new file mode 100644 index 0000000..304dc6a --- /dev/null +++ b/tests/entries.bats @@ -0,0 +1,14 @@ +@test "Firefox desktop entry and all its actions are extracted" { + run ../sway-launcher-desktop.sh entries data/firefox.desktop + [ "$status" -eq 0 ] + [[ ${lines[0]} =~ data/firefox.desktop ]] + [[ ${lines[0]} =~ ^data/firefox.desktop.*Firefox ]] + [[ ${lines[1]} =~ ^data/firefox.desktop.*Firefox.*(New Window).*new-window ]] + [[ ${lines[2]} =~ ^data/firefox.desktop.*Firefox.*(New Private Window).*new-private-window ]] +} + +@test "Wildcard expansion works for extraction of desktop files" { + run ../sway-launcher-desktop.sh entries data/*.desktop + [ "$status" -eq 0 ] + [[ ${#lines[@]} == 5 ]] +}
\ No newline at end of file |
