diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-11-28 18:42:22 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-11-28 18:42:22 +0100 |
commit | c6c7152b6e2926437a0977ed1735c42289829919 (patch) | |
tree | a21c80aefe06fb25c4947d4b230de01211614685 /script | |
parent | a61d85ac24482ec2cfebd1d4a0d8b3a95ed53cd4 (diff) |
If no XDG_DATA_DIRS set, try to deduce the dirs from PATH.
Diffstat (limited to 'script')
-rwxr-xr-x | script/rofi-theme-selector | 28 |
1 files 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}" ] |