]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/blob - contrib/bash_completion/autorandr
e7f098c1b4474db3596c2e659fbf74e80b469feb
[deb_pkgs/autorandr.git] / contrib / bash_completion / autorandr
1 # autorandr/auto-disper completion by Maciej 'macieks' Sitarz <macieks@freesco.pl>
2 # XDG additions and service dir filtering by Vladimir-csp
3
4 _autorandr ()
5 {
6         local cur prev opts lopts prfls AR_DIRS OIFS
7
8         COMPREPLY=()
9         cur="${COMP_WORDS[COMP_CWORD]}"
10         prev="${COMP_WORDS[COMP_CWORD-1]}"
11
12         opts="-h -c -s -r -l -d"
13         lopts="--help --change --save --remove --load --default --force --fingerprint --config --dry-run"
14
15         # find system-level autorandr dirs
16         OIFS="$IFS"
17         IFS=':'
18                 for DIR in ${XDG_CONFIG_DIRS:-/etc/xdg}
19                 do
20                         IFS="$OIFS"
21                         [ -d "$DIR/autorandr" ] && AR_DIRS=( "${AR_DIRS[@]}" "$DIR/autorandr" )
22                 done
23         IFS="$OIFS"
24
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/" )
30         fi
31
32         if [ -n "${AR_DIRS}" ]
33         then
34                 prfls="$(find "${AR_DIRS[@]}" -mindepth 1 -maxdepth 1 -type d ! -name "*.d" -printf '%f\n' | sort -u)"
35         else
36                 prfls=""
37         fi
38
39         case "${cur}" in
40                 --*)
41                         COMPREPLY=( $( compgen -W "${lopts}" -- $cur ) )
42                         return 0
43                         ;;
44                 -*)
45                         COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) )
46                         return 0
47                         ;;
48                 *)
49                         if [ $COMP_CWORD -eq 1 ]; then
50                                 COMPREPLY=( $( compgen -W "${opts} ${lopts}" -- $cur ) )
51                         fi
52                         ;;
53                 esac
54
55         case "${prev}" in
56                 -r|--remove|-l|--load|-d|--default)
57                         COMPREPLY=( $( compgen -W "${prfls}" -- $cur ) )
58                         return 0
59                         ;;
60                 *)
61                         ;;
62         esac
63
64         return 0
65 }
66 complete -F _autorandr autorandr