X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=contrib%2Fbash_completion%2Fautorandr;h=e7f098c1b4474db3596c2e659fbf74e80b469feb;hb=8e911c88fae965ebeff6f2d0509755ab2bed498d;hp=7a8b81b5dc4d0714619c5e3bbdd760d78ba20dd3;hpb=0e7fb8b21d6cf02a78b2ea48467ce02cd4badfb7;p=deb_pkgs%2Fautorandr.git diff --git a/contrib/bash_completion/autorandr b/contrib/bash_completion/autorandr index 7a8b81b..e7f098c 100644 --- a/contrib/bash_completion/autorandr +++ b/contrib/bash_completion/autorandr @@ -1,19 +1,37 @@ # autorandr/auto-disper completion by Maciej 'macieks' Sitarz +# 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 -l -d" - lopts="--help --change --save --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'`" + opts="-h -c -s -r -l -d" + lopts="--help --change --save --remove --load --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 [ -n "${AR_DIRS}" ] + then + prfls="$(find "${AR_DIRS[@]}" -mindepth 1 -maxdepth 1 -type d ! -name "*.d" -printf '%f\n' | sort -u)" else prfls="" fi @@ -35,7 +53,7 @@ _autorandr () esac case "${prev}" in - -l|--load|-d|--default) + -r|--remove|-l|--load|-d|--default) COMPREPLY=( $( compgen -W "${prfls}" -- $cur ) ) return 0 ;;