1 |
1 |
2 if [[ -s ~/.bash_completion.d ]]; then |
2 # user commands see only users |
3 for f in ~/.bash_completion.d/* ~/.bash_completion.d/.*; do |
3 complete -u su passwd write chfn groups slay w sux |
4 . $f |
4 |
|
5 # bg completes with stopped jobs |
|
6 complete -A stopped -P '"%' -S '"' bg |
|
7 |
|
8 # other job commands |
|
9 complete -j -P '"%' -S '"' fg jobs disown |
|
10 |
|
11 # readonly and unset complete with shell variables |
|
12 complete -v readonly unset |
|
13 |
|
14 # set completes with set options |
|
15 complete -A setopt set |
|
16 |
|
17 # shopt completes with shopt options |
|
18 complete -A shopt shopt |
|
19 |
|
20 # helptopics |
|
21 complete -A helptopic help |
|
22 |
|
23 # unalias completes with aliases |
|
24 complete -a unalias |
|
25 |
|
26 # bind completes with readline bindings (make this more intelligent) |
|
27 complete -A binding bind |
|
28 |
|
29 # type and which complete on commands |
|
30 complete -c command type which |
|
31 |
|
32 # builtin completes on builtins |
|
33 complete -b builtin |
|
34 |
|
35 _hgsyncew() { |
|
36 local cur=${COMP_WORDS[COMP_CWORD]} |
|
37 COMPREPLY=( $(compgen -W "--push" -- $cur) ) |
|
38 return 0 |
|
39 } |
|
40 complete -F _hgsyncew -o nospace hgsyncew |
|
41 |
|
42 _pathsearch() { |
|
43 local prev cur=${COMP_WORDS[COMP_CWORD]} |
|
44 [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]} |
|
45 if [[ $prev = -d ]]; then |
|
46 COMPREPLY=() |
|
47 return 0 |
|
48 fi |
|
49 case "$cur" in |
|
50 -*) COMPREPLY=( $(compgen -W "-d --delimiter= -h --help" -- $cur ) ) ;; |
|
51 *) COMPREPLY=() ;; |
|
52 esac |
|
53 return 0 |
|
54 } |
|
55 complete -F _pathsearch -o nospace pathsearch |
|
56 |
|
57 _mycd() { |
|
58 local cur |
|
59 cur=${COMP_WORDS[COMP_CWORD]} |
|
60 if [[ -z "${CDPATH:-}" || "$cur" == ?(.)?(.)/* ]]; then |
|
61 COMPREPLY=( $(compgen -d -- "$cur") ) |
|
62 return 0 |
|
63 fi |
|
64 local i j k |
|
65 for i in ${CDPATH//:/$'\n'}; do |
|
66 k="${#COMPREPLY[@]}" |
|
67 for j in $( compgen -d -- $i/$cur ); do |
|
68 COMPREPLY[k++]=${j#$i/} |
|
69 done |
5 done |
70 done |
6 fi |
71 return 0 |
|
72 } |
|
73 complete -F _mycd -o nospace cd |
7 |
74 |
8 # Local variables: |
75 _man() { |
9 # mode: shell-script |
76 local p |
10 # End: |
77 local cur=${COMP_WORDS[COMP_CWORD]} |
|
78 if [[ $cur = /* || $cur = ./* ]]; then |
|
79 COMPREPLY=( $(compgen -f -- $cur) ) |
|
80 fi |
|
81 local IFS=': |
|
82 ' |
|
83 for p in /usr/share/man $MANPATH; do |
|
84 [[ -n $p ]] || continue |
|
85 p=( $p/man*/* ) |
|
86 p=( ${p[@]##*/} ) |
|
87 p=( ${p[@]%.gz} ) |
|
88 p=( ${p[@]%.*} ) |
|
89 p=( $(compgen -W '${p[@]}' -- $cur ) ) |
|
90 COMPREPLY=( ${COMPREPLY[@]} ${p[@]} ) |
|
91 done |
|
92 } |
|
93 complete -F _man man |
|
94 |
|
95 _make() { |
|
96 local i mk |
|
97 local dir=. |
|
98 local cur=${COMP_WORDS[COMP_CWORD]} |
|
99 if [[ $cur = -* ]]; then |
|
100 COMPREPLY=( $(compgen -W "-C -f" -- "$cur") ) |
|
101 return 0 |
|
102 fi |
|
103 [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]} |
|
104 for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do |
|
105 case ${COMP_WORDS[i]} in |
|
106 -f) mk=${COMP_WORDS[i+1]} ;; |
|
107 -C) dir=${COMP_WORDS[i+1]} ;; |
|
108 esac |
|
109 done |
|
110 if [[ $prev = -C ]]; then |
|
111 COMPREPLY=( $(compgen -d -- "$cur") ) |
|
112 return 0 |
|
113 fi |
|
114 if [[ $prev = -f ]]; then |
|
115 COMPREPLY=( $(cd $dir >/dev/null 2>&1; compgen -f -- "$cur") ) |
|
116 return 0 |
|
117 fi |
|
118 mk=$dir/$mk |
|
119 [[ -f $mk ]] || mk=$(eval echo $dir/[Mm]akefile) |
|
120 [[ -f $mk ]] || return 1 |
|
121 COMPREPLY=( $(compgen -W "$(sed -n -e '/^[[:alnum:]_-]*:/{s=^\([^:]*\):.*=\1=;p;}' $mk)" -- $cur) ) |
|
122 return 0 |
|
123 } |
|
124 complete -F _make make gmake pmake |
|
125 |
|
126 _cygcheck() { |
|
127 local opt |
|
128 local cur=${COMP_WORDS[COMP_CWORD]} |
|
129 case $COMP_CWORD in |
|
130 1) |
|
131 case $cur in |
|
132 -*) |
|
133 COMPREPLY=( $(compgen -W "-v --verbose -h --help -V --version -c --check-setup -s --sysinfo |
|
134 -k --keycheck -f --find-package -l --list-package -p --package-query" -- "$cur") ) |
|
135 return 0 ;; |
|
136 *) |
|
137 COMPREPLY=( $(compgen -c -- "$cur") ) |
|
138 return 0 ;; |
|
139 esac |
|
140 ;; |
|
141 2) |
|
142 opt=${COMP_WORDS[1]} |
|
143 case $opt in |
|
144 -c|--check-setup|-l|--list-package) |
|
145 pkgs=( /etc/setup/*.lst.gz ) |
|
146 pkgs=( ${pkgs[@]##*/} ) |
|
147 pkgs=( ${pkgs[@]%.lst.gz} ) |
|
148 COMPREPLY=( $(compgen -W '${pkgs[@]}' -- $cur ) ) |
|
149 return 0;; |
|
150 esac |
|
151 return 0;; |
|
152 esac |
|
153 return 0 |
|
154 } |
|
155 complete -F _cygcheck cygcheck.exe cygcheck |
|
156 |