.bashrc
changeset 283 eb383cf7ba80
parent 282 3710f0a122cd
child 284 3351fda649d5
equal deleted inserted replaced
282:3710f0a122cd 283:eb383cf7ba80
   129 bind '"\ee": edit-and-execute-command'
   129 bind '"\ee": edit-and-execute-command'
   130 
   130 
   131 ################################################################
   131 ################################################################
   132 # Completion.
   132 # Completion.
   133 
   133 
   134 # user commands see only users
   134 # Use system wide completion, if available.
   135 complete -u su passwd write chfn groups slay w sux
       
   136 
       
   137 # bg completes with stopped jobs
       
   138 complete -A stopped -P '"%' -S '"' bg
       
   139 
       
   140 # other job commands
       
   141 complete -j -P '"%' -S '"' fg jobs disown
       
   142 
       
   143 # readonly and unset complete with shell variables
       
   144 complete -v readonly unset
       
   145 
       
   146 # set completes with set options
       
   147 complete -A setopt set
       
   148 
       
   149 # shopt completes with shopt options
       
   150 complete -A shopt shopt
       
   151 
       
   152 # helptopics
       
   153 complete -A helptopic help
       
   154 
       
   155 # unalias completes with aliases
       
   156 complete -a unalias
       
   157 
       
   158 # bind completes with readline bindings (make this more intelligent)
       
   159 complete -A binding bind
       
   160 
       
   161 # type and which complete on commands
       
   162 complete -c command type which
       
   163 
       
   164 # builtin completes on builtins
       
   165 complete -b builtin
       
   166 
       
   167 _hgsyncew() {
       
   168   local cur=${COMP_WORDS[COMP_CWORD]}
       
   169   COMPREPLY=( $(compgen -W "--push" -- $cur) )
       
   170   return 0
       
   171 }
       
   172 complete -F _hgsyncew -o nospace hgsyncew
       
   173 
       
   174 _pathsearch() {
       
   175   local prev cur=${COMP_WORDS[COMP_CWORD]}
       
   176   [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]}
       
   177   if [[ $prev = -d ]]; then
       
   178     COMPREPLY=()
       
   179     return 0
       
   180   fi
       
   181   case "$cur" in
       
   182     -*) COMPREPLY=( $(compgen -W "-d --delimiter= -h --help" -- $cur ) ) ;;
       
   183     *) COMPREPLY=() ;;
       
   184   esac
       
   185   return 0
       
   186 }
       
   187 complete -F _pathsearch -o nospace pathsearch
       
   188 
       
   189 _mycd() {
       
   190   local cur
       
   191   cur=${COMP_WORDS[COMP_CWORD]}
       
   192   if [[ -z "${CDPATH:-}" || "$cur" == ?(.)?(.)/* ]]; then
       
   193     COMPREPLY=( $(compgen -d -- "$cur") )
       
   194     return 0
       
   195   fi
       
   196   local i j k
       
   197   for i in ${CDPATH//:/$'\n'}; do
       
   198     k="${#COMPREPLY[@]}"
       
   199     for j in $( compgen -d -- $i/$cur ); do
       
   200       COMPREPLY[k++]=${j#$i/}
       
   201     done
       
   202   done
       
   203   return 0
       
   204 }
       
   205 complete -F _mycd -o nospace cd
       
   206 
       
   207 _man() {
       
   208   local p
       
   209   local cur=${COMP_WORDS[COMP_CWORD]}
       
   210   if [[ $cur = /* || $cur = ./* ]]; then
       
   211     COMPREPLY=( $(compgen -f -- $cur) )
       
   212   fi
       
   213   local IFS=':
       
   214 '
       
   215   for p in /usr/share/man $MANPATH; do
       
   216     [[ -n $p ]] || continue
       
   217     p=( $p/man*/* )
       
   218     p=( ${p[@]##*/} )
       
   219     p=( ${p[@]%.gz} )
       
   220     p=( ${p[@]%.*} )
       
   221     p=( $(compgen -W '${p[@]}' -- $cur ) )
       
   222     COMPREPLY=( ${COMPREPLY[@]} ${p[@]} )
       
   223   done
       
   224 }
       
   225 complete -F _man man
       
   226 
       
   227 _make() {
       
   228   local i mk
       
   229   local dir=.
       
   230   local cur=${COMP_WORDS[COMP_CWORD]}
       
   231   if [[ $cur = -* ]]; then
       
   232     COMPREPLY=( $(compgen -W "-C -f" -- "$cur") )
       
   233     return 0
       
   234   fi
       
   235   [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]}
       
   236   for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do
       
   237     case ${COMP_WORDS[i]} in
       
   238       -f) mk=${COMP_WORDS[i+1]} ;;
       
   239       -C) dir=${COMP_WORDS[i+1]} ;;
       
   240     esac
       
   241   done
       
   242   if [[ $prev = -C ]]; then
       
   243     COMPREPLY=( $(compgen -d -- "$cur") )
       
   244     return 0
       
   245   fi
       
   246   if [[ $prev = -f ]]; then
       
   247     COMPREPLY=( $(cd $dir >/dev/null 2>&1; compgen -f -- "$cur") )
       
   248     return 0
       
   249   fi
       
   250   mk=$dir/$mk
       
   251   [[ -f $mk ]] || mk=$(eval echo $dir/[Mm]akefile)
       
   252   [[ -f $mk ]] || return 1
       
   253   COMPREPLY=( $(compgen -W "$(sed -n -e '/^[[:alnum:]_-]*:/{s=^\([^:]*\):.*=\1=;p;}' $mk)" -- $cur) )
       
   254   return 0
       
   255 }
       
   256 complete -F _make make gmake pmake
       
   257 
       
   258 _cygcheck() {
       
   259   local opt
       
   260   local cur=${COMP_WORDS[COMP_CWORD]}
       
   261   case $COMP_CWORD in
       
   262     1)
       
   263       case $cur in
       
   264         -*)
       
   265           COMPREPLY=( $(compgen -W "-v --verbose -h --help -V --version -c --check-setup -s --sysinfo
       
   266             -k --keycheck -f --find-package -l --list-package -p --package-query" -- "$cur") )
       
   267           return 0 ;;
       
   268         *)
       
   269           COMPREPLY=( $(compgen -c -- "$cur") )
       
   270           return 0 ;;
       
   271       esac
       
   272       ;;
       
   273     2)
       
   274       opt=${COMP_WORDS[1]}
       
   275       case $opt in
       
   276         -c|--check-setup|-l|--list-package)
       
   277           pkgs=( /etc/setup/*.lst.gz )
       
   278           pkgs=( ${pkgs[@]##*/} )
       
   279           pkgs=( ${pkgs[@]%.lst.gz} )
       
   280           COMPREPLY=( $(compgen -W '${pkgs[@]}' -- $cur ) )
       
   281           return 0;;
       
   282       esac
       
   283       return 0;;
       
   284   esac
       
   285   return 0
       
   286 }
       
   287 complete -F _cygcheck cygcheck.exe cygcheck
       
   288 
       
   289 # Use bash-completion, if available.
       
   290 if [ -f /etc/bash_completion ]; then
   135 if [ -f /etc/bash_completion ]; then
   291   # Under Cygwin bash completition start a long time.
   136   # Under Cygwin bash completition take a long time for starting.
   292   if [ ! "$OSTYPE" = cygwin ]; then
   137   if [ ! "$OSTYPE" = cygwin ]; then
   293     . /etc/bash_completion
   138     . /etc/bash_completion
   294   else
       
   295     # But load local completion anyway.
       
   296     if [ -f ~/.bash_completion ]; then
       
   297       . ~/.bash_completion
       
   298     fi
       
   299   fi
   139   fi
   300 fi
   140 elif [ -f $HOME/usr/etc/bash_completion ]; then
   301 if [ -f $HOME/usr/etc/bash_completion ]; then
       
   302   . $HOME/usr/etc/bash_completion
   141   . $HOME/usr/etc/bash_completion
   303 fi
   142 fi
       
   143 # Load local completions.
       
   144 if [ -f ~/.bash_completion ]; then
       
   145   . ~/.bash_completion
       
   146 fi
       
   147 if [ -d ~/.bash_completion.d ]; then
       
   148   for f in ~/.bash_completion.d/* ~/.bash_completion.d/.*; do
       
   149     . $f
       
   150   done
       
   151 fi
       
   152