1 # autorandr/auto-disper completion by Maciej 'macieks' Sitarz <macieks@freesco.pl>
2 # XDG additions and service dir filtering by Vladimir-csp
6 local cur prev opts lopts prfls AR_DIRS OIFS
9 cur="${COMP_WORDS[COMP_CWORD]}"
10 prev="${COMP_WORDS[COMP_CWORD-1]}"
12 opts="-h -c -s -r -l -d"
13 lopts="--help --change --save --remove --load --default --force --fingerprint --config --dry-run"
15 # find system-level autorandr dirs
18 for DIR in ${XDG_CONFIG_DIRS:-/etc/xdg}
21 [ -d "$DIR/autorandr" ] && AR_DIRS=( "${AR_DIRS[@]}" "$DIR/autorandr" )
25 # find user-level autorandr dir
26 if [ -d "$HOME/.autorandr" ]; then
27 AR_DIRS=( "${AR_DIRS[@]}" "$HOME/.autorandr" )
28 elif [ -d "${XDG_CONFIG_HOME:-$HOME/.config}/autorandr/" ]; then
29 AR_DIRS=( "${AR_DIRS[@]}" "${XDG_CONFIG_HOME:-$HOME/.config}/autorandr/" )
32 if [ -n "${AR_DIRS}" ]
34 prfls="$(find "${AR_DIRS[@]}" -mindepth 1 -maxdepth 1 -type d ! -name "*.d" -printf '%f\n' | sort -u)"
41 COMPREPLY=( $( compgen -W "${lopts}" -- $cur ) )
45 COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) )
49 if [ $COMP_CWORD -eq 1 ]; then
50 COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) )
56 -r|--remove|-l|--load|-d|--default)
57 COMPREPLY=( $( compgen -W "${prfls}" -- $cur ) )
66 complete -F _autorandr autorandr