From 2ce0cfb1463c2ea33679d0572d96310fbcb6f1e7 Mon Sep 17 00:00:00 2001 From: cswimr Date: Mon, 14 Oct 2024 13:37:00 -0400 Subject: [PATCH] cleaned up does-desktop-entry-exist --- .zshc/func.zsh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.zshc/func.zsh b/.zshc/func.zsh index cb1b19b..ac5ce48 100644 --- a/.zshc/func.zsh +++ b/.zshc/func.zsh @@ -162,16 +162,25 @@ function flameshot-screenshot { function does-desktop-entry-exist { readonly desktopentry=${1:?Please provide the full filename of the desktop entry.} - local entrypaths=( - "/usr/share/applications" - "/usr/local/share/applications" - "$HOME/.local/share/applications" - ) + + if (( $+commands[qtpaths] )); then + local entrypaths=("${(@f)$(qtpaths --paths ApplicationsLocation | tr ':' '\n')}") + else + echo "qtpaths is not installed, falling back to XDG_DATA_DIRS." + local entrypaths=(${(f)"$(echo $XDG_DATA_DIRS | tr ':' '\n' | sed 's|$|/applications|')"}) + entrypaths+=("$HOME/.local/share/applications") + fi + + echo "Checking the following paths for $desktopentry:\n${(F)entrypaths}\n--------------------" + for entrypath in "${entrypaths[@]}"; do + echo "Checking for $entrypath/$desktopentry" if [[ -f "$entrypath/$desktopentry" ]]; then + echo "$desktopentry found in $entrypath" return 0 fi done + echo "Desktop entry $desktopentry does not exist." return 1 }