From c6c7152b6e2926437a0977ed1735c42289829919 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 28 Nov 2016 18:42:22 +0100 Subject: [PATCH] If no XDG_DATA_DIRS set, try to deduce the dirs from PATH. --- script/rofi-theme-selector | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/script/rofi-theme-selector b/script/rofi-theme-selector index 51e3a325..15320c10 100755 --- a/script/rofi-theme-selector +++ b/script/rofi-theme-selector @@ -40,15 +40,35 @@ declare -a theme_names function find_themes() { DIRS=${XDG_DATA_DIRS} + OLDIFS=${IFS} + IFS=: if [ -z "${XDG_DATA_DIRS}" ] then - echo "XDG_DATA_DIRS needs to be set for this script to function." - exit 1; + echo "XDG_DATA_DIRS needs to be set for this script to function correctly." + echo -n "Using dirs from \$PATH: " + DIRS= + # Iterate over items in $PATH + for p in ${PATH}; do + # Remove trailing / if exists. + x=${p%/} + # remove both /bin and /sbin and /games from end + x=${x%/bin} + x=${x%/sbin} + x=${x%/games} + # Add /share + x=${x}/share + # Check if entry exists Prepend : so :${x}: matches nicely + case ":${DIRS}" in + *$x:*);; + *) DIRS+="$x:";; + esac + done + # Remove trailing : + DIRS=${DIRS%:} + echo "${DIRS}" fi # Add user dir. DIRS+=":${HOME}/.local/share/" - OLDIFS=${IFS} - IFS=: for p in ${DIRS}; do TD=${p}rofi/themes/ if [ -n "${p}" ] && [ -d "${TD}" ]