]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blobdiff - contrib/bash_completion/autorandr
Add new options to completion files
[deb_pkgs/autorandr.git] / contrib / bash_completion / autorandr
index a106b7e2ff3bb3ed82edf3a7f31571dacd2cb189..904ef8035e557e34a20b381d6a3ccbe9872b1418 100644 (file)
@@ -1,19 +1,37 @@
 # autorandr/auto-disper completion by Maciej 'macieks' Sitarz <macieks@freesco.pl>
+# XDG additions and service dir filtering by Vladimir-csp
 
 _autorandr ()
 {
-       local cur prev opts lopts prfls
+       local cur prev opts lopts prfls AR_DIRS OIFS
 
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
 
        opts="-h -c -s -r -l -d"
-       lopts="--help --change --save --remove --load --default --force --fingerprint --config --dry-run"
-       if [ -d ~/.autorandr ]; then
-               prfls="`find ~/.autorandr/* -maxdepth 1 -type d -printf '%f\n'`"
-       elif [ -d ~/.config/autorandr ]; then
-               prfls="`find ~/.config/autorandr/* -maxdepth 1 -type d -printf '%f\n'`"
+       lopts="--help --change --cycle --save --remove --load --list --default --force --fingerprint --config --dry-run"
+
+       # find system-level autorandr dirs
+       OIFS="$IFS"
+       IFS=':'
+               for DIR in ${XDG_CONFIG_DIRS:-/etc/xdg}
+               do
+                       IFS="$OIFS"
+                       [ -d "$DIR/autorandr" ] && AR_DIRS=( "${AR_DIRS[@]}" "$DIR/autorandr" )
+               done
+       IFS="$OIFS"
+
+       # find user-level autorandr dir
+       if [ -d "$HOME/.autorandr" ]; then
+               AR_DIRS=( "${AR_DIRS[@]}" "$HOME/.autorandr" )
+       elif [ -d "${XDG_CONFIG_HOME:-$HOME/.config}/autorandr/" ]; then
+               AR_DIRS=( "${AR_DIRS[@]}" "${XDG_CONFIG_HOME:-$HOME/.config}/autorandr/" )
+       fi
+
+       if [ "${#AR_DIRS[@]}" -gt 0 ]
+       then
+               prfls="$(find "${AR_DIRS[@]}" -mindepth 1 -maxdepth 1 -type d ! -name "*.d" -printf '%f\n' 2>/dev/null | sort -u)"
        else
                prfls=""
        fi