From abcb891359649559981d0ef522ed16ddf2b68908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20Mei=C3=9Felbach?= Date: Thu, 31 Oct 2019 21:40:32 +0100 Subject: Generate a spec-conformant "desktop file id" of each .desktop file and remove duplicates. This should process user-specific overrides properly #3 --- sway-launcher-desktop.sh | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'sway-launcher-desktop.sh') diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh index a73ac70..102ab9f 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,10 +15,12 @@ TERMINAL_COMMAND="${TERMINAL_COMMAND:="termite -e"}" GLYPH_COMMAND=" " GLYPH_DESKTOP=" " HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-history.txt" + +# TODO: Actually follow spec here: https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html DIRS=( - /usr/share/applications "$HOME/.local/share/applications" /usr/local/share/applications + /usr/share/applications ) function describe() { @@ -36,8 +38,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 +80,7 @@ function entries() { print FILENAME "\034desktop\034\033[33m" pre name "\033[0m (" actions[i, "name"] ")\034" actions[i, "key"] } }' \ - "$@" >"$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]}/**/*.desktop" + fi +done +# shellcheck disable=SC2068 +entries ${DIRS[@]} >>"$FZFPIPE" +#) & # Load and append command list ( -- cgit v1.2.3