diff options
| author | Moritz Meißelbach <arbelzapf@gmail.com> | 2019-11-08 21:25:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-08 21:25:28 +0100 |
| commit | 8b8c4b3bf7e6053061aafb880bb7084cea6ef6f4 (patch) | |
| tree | 9b63ea96eea4476fc3676581d5d31afc75b26946 /sway-launcher-desktop.sh | |
| parent | ac656f120a12e3521c4cabbc96e0363f746193a4 (diff) | |
| parent | 9dc1986ab0aa0021d4a2c74e39bd5913a8f7141b (diff) | |
| download | sway-launcher-desktop-8b8c4b3bf7e6053061aafb880bb7084cea6ef6f4.tar.gz sway-launcher-desktop-8b8c4b3bf7e6053061aafb880bb7084cea6ef6f4.zip | |
Merge pull request #4 from Biont/desktop_file_ids
Follow some more XDG Base Directory specifications, resulting in duplicate entries no longer showing up and support of custom/extended XDG_DATA_DIRS setups
Diffstat (limited to 'sway-launcher-desktop.sh')
| -rwxr-xr-x | sway-launcher-desktop.sh | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh index a73ac70..23b11e5 100755 --- a/sway-launcher-desktop.sh +++ b/sway-launcher-desktop.sh @@ -2,7 +2,7 @@ # 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 +shopt -s nullglob globstar set -o pipefail # shellcheck disable=SC2154 trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR @@ -15,11 +15,10 @@ 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 -) + +# Get locations of desktop application folders according to spec +# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html +IFS=':' read -ra DIRS <<< "${XDG_CONFIG_HOME-${HOME}/.config}:${XDG_DATA_DIRS-/usr/local/share:/usr/share}" function describe() { if [[ $2 == 'command' ]]; then @@ -36,8 +35,24 @@ function describe() { } function entries() { + # shellcheck disable=SC2068 awk -v pre="$GLYPH_DESKTOP" -F= ' - BEGINFILE{application=0;block="";a=0} + function desktopFileID(filename){ + sub("^.*applications/", "", filename); + sub("/", "-", filename); + return filename + } + BEGINFILE{ + id=desktopFileID(FILENAME) + if(id in fileIds){ + exit; + }else{ + fileIds[id]=0 + } + application=0; + block=""; + a=0 + } /^\[Desktop Entry\]/{block="entry"} /^Type=Application/{application=1} /^\[Desktop Action/{ @@ -62,7 +77,7 @@ function entries() { print FILENAME "\034desktop\034\033[33m" pre name "\033[0m (" actions[i, "name"] ")\034" actions[i, "key"] } }' \ - "$@" </dev/null + $@ </dev/null # the empty stdin is needed in case no *.desktop files } @@ -134,12 +149,17 @@ trap 'rm "$FZFPIPE" "$PIDFILE"' EXIT INT (printf '%s' "${HIST_LINES[@]#* }" >>"$FZFPIPE") & # Load and append Desktop entries -( - for dir in "${DIRS[@]}"; do - [[ -d "$dir" ]] || continue - entries "$dir"/*.desktop >>"$FZFPIPE" - done -) & +#( +for i in "${!DIRS[@]}"; do + if [[ ! -d "${DIRS[i]}" ]]; then + unset -v 'DIRS[$i]' + else + DIRS[$i]="${DIRS[i]}/applications/**/*.desktop" + fi +done +# shellcheck disable=SC2068 +entries ${DIRS[@]} >>"$FZFPIPE" +#) & # Load and append command list ( |
