# HG changeset patch # User Oleksandr Gavenko # Date 1325522095 -7200 # Node ID eb383cf7ba8062e849261cb6954bce1e9a1db394 # Parent 3710f0a122cd87b525493aad6f1ba638898d4c20 Move completions to separate file. diff -r 3710f0a122cd -r eb383cf7ba80 .bash_completion --- a/.bash_completion Mon Jan 02 18:13:50 2012 +0200 +++ b/.bash_completion Mon Jan 02 18:34:55 2012 +0200 @@ -1,10 +1,156 @@ -if [[ -s ~/.bash_completion.d ]]; then - for f in ~/.bash_completion.d/* ~/.bash_completion.d/.*; do - . $f +# user commands see only users +complete -u su passwd write chfn groups slay w sux + +# bg completes with stopped jobs +complete -A stopped -P '"%' -S '"' bg + +# other job commands +complete -j -P '"%' -S '"' fg jobs disown + +# readonly and unset complete with shell variables +complete -v readonly unset + +# set completes with set options +complete -A setopt set + +# shopt completes with shopt options +complete -A shopt shopt + +# helptopics +complete -A helptopic help + +# unalias completes with aliases +complete -a unalias + +# bind completes with readline bindings (make this more intelligent) +complete -A binding bind + +# type and which complete on commands +complete -c command type which + +# builtin completes on builtins +complete -b builtin + +_hgsyncew() { + local cur=${COMP_WORDS[COMP_CWORD]} + COMPREPLY=( $(compgen -W "--push" -- $cur) ) + return 0 +} +complete -F _hgsyncew -o nospace hgsyncew + +_pathsearch() { + local prev cur=${COMP_WORDS[COMP_CWORD]} + [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]} + if [[ $prev = -d ]]; then + COMPREPLY=() + return 0 + fi + case "$cur" in + -*) COMPREPLY=( $(compgen -W "-d --delimiter= -h --help" -- $cur ) ) ;; + *) COMPREPLY=() ;; + esac + return 0 +} +complete -F _pathsearch -o nospace pathsearch + +_mycd() { + local cur + cur=${COMP_WORDS[COMP_CWORD]} + if [[ -z "${CDPATH:-}" || "$cur" == ?(.)?(.)/* ]]; then + COMPREPLY=( $(compgen -d -- "$cur") ) + return 0 + fi + local i j k + for i in ${CDPATH//:/$'\n'}; do + k="${#COMPREPLY[@]}" + for j in $( compgen -d -- $i/$cur ); do + COMPREPLY[k++]=${j#$i/} + done done -fi + return 0 +} +complete -F _mycd -o nospace cd + +_man() { + local p + local cur=${COMP_WORDS[COMP_CWORD]} + if [[ $cur = /* || $cur = ./* ]]; then + COMPREPLY=( $(compgen -f -- $cur) ) + fi + local IFS=': +' + for p in /usr/share/man $MANPATH; do + [[ -n $p ]] || continue + p=( $p/man*/* ) + p=( ${p[@]##*/} ) + p=( ${p[@]%.gz} ) + p=( ${p[@]%.*} ) + p=( $(compgen -W '${p[@]}' -- $cur ) ) + COMPREPLY=( ${COMPREPLY[@]} ${p[@]} ) + done +} +complete -F _man man -# Local variables: -# mode: shell-script -# End: +_make() { + local i mk + local dir=. + local cur=${COMP_WORDS[COMP_CWORD]} + if [[ $cur = -* ]]; then + COMPREPLY=( $(compgen -W "-C -f" -- "$cur") ) + return 0 + fi + [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]} + for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do + case ${COMP_WORDS[i]} in + -f) mk=${COMP_WORDS[i+1]} ;; + -C) dir=${COMP_WORDS[i+1]} ;; + esac + done + if [[ $prev = -C ]]; then + COMPREPLY=( $(compgen -d -- "$cur") ) + return 0 + fi + if [[ $prev = -f ]]; then + COMPREPLY=( $(cd $dir >/dev/null 2>&1; compgen -f -- "$cur") ) + return 0 + fi + mk=$dir/$mk + [[ -f $mk ]] || mk=$(eval echo $dir/[Mm]akefile) + [[ -f $mk ]] || return 1 + COMPREPLY=( $(compgen -W "$(sed -n -e '/^[[:alnum:]_-]*:/{s=^\([^:]*\):.*=\1=;p;}' $mk)" -- $cur) ) + return 0 +} +complete -F _make make gmake pmake + +_cygcheck() { + local opt + local cur=${COMP_WORDS[COMP_CWORD]} + case $COMP_CWORD in + 1) + case $cur in + -*) + COMPREPLY=( $(compgen -W "-v --verbose -h --help -V --version -c --check-setup -s --sysinfo + -k --keycheck -f --find-package -l --list-package -p --package-query" -- "$cur") ) + return 0 ;; + *) + COMPREPLY=( $(compgen -c -- "$cur") ) + return 0 ;; + esac + ;; + 2) + opt=${COMP_WORDS[1]} + case $opt in + -c|--check-setup|-l|--list-package) + pkgs=( /etc/setup/*.lst.gz ) + pkgs=( ${pkgs[@]##*/} ) + pkgs=( ${pkgs[@]%.lst.gz} ) + COMPREPLY=( $(compgen -W '${pkgs[@]}' -- $cur ) ) + return 0;; + esac + return 0;; + esac + return 0 +} +complete -F _cygcheck cygcheck.exe cygcheck + diff -r 3710f0a122cd -r eb383cf7ba80 .bashrc --- a/.bashrc Mon Jan 02 18:13:50 2012 +0200 +++ b/.bashrc Mon Jan 02 18:34:55 2012 +0200 @@ -131,173 +131,22 @@ ################################################################ # Completion. -# user commands see only users -complete -u su passwd write chfn groups slay w sux - -# bg completes with stopped jobs -complete -A stopped -P '"%' -S '"' bg - -# other job commands -complete -j -P '"%' -S '"' fg jobs disown - -# readonly and unset complete with shell variables -complete -v readonly unset - -# set completes with set options -complete -A setopt set - -# shopt completes with shopt options -complete -A shopt shopt - -# helptopics -complete -A helptopic help - -# unalias completes with aliases -complete -a unalias - -# bind completes with readline bindings (make this more intelligent) -complete -A binding bind - -# type and which complete on commands -complete -c command type which - -# builtin completes on builtins -complete -b builtin - -_hgsyncew() { - local cur=${COMP_WORDS[COMP_CWORD]} - COMPREPLY=( $(compgen -W "--push" -- $cur) ) - return 0 -} -complete -F _hgsyncew -o nospace hgsyncew - -_pathsearch() { - local prev cur=${COMP_WORDS[COMP_CWORD]} - [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]} - if [[ $prev = -d ]]; then - COMPREPLY=() - return 0 - fi - case "$cur" in - -*) COMPREPLY=( $(compgen -W "-d --delimiter= -h --help" -- $cur ) ) ;; - *) COMPREPLY=() ;; - esac - return 0 -} -complete -F _pathsearch -o nospace pathsearch - -_mycd() { - local cur - cur=${COMP_WORDS[COMP_CWORD]} - if [[ -z "${CDPATH:-}" || "$cur" == ?(.)?(.)/* ]]; then - COMPREPLY=( $(compgen -d -- "$cur") ) - return 0 - fi - local i j k - for i in ${CDPATH//:/$'\n'}; do - k="${#COMPREPLY[@]}" - for j in $( compgen -d -- $i/$cur ); do - COMPREPLY[k++]=${j#$i/} - done - done - return 0 -} -complete -F _mycd -o nospace cd - -_man() { - local p - local cur=${COMP_WORDS[COMP_CWORD]} - if [[ $cur = /* || $cur = ./* ]]; then - COMPREPLY=( $(compgen -f -- $cur) ) - fi - local IFS=': -' - for p in /usr/share/man $MANPATH; do - [[ -n $p ]] || continue - p=( $p/man*/* ) - p=( ${p[@]##*/} ) - p=( ${p[@]%.gz} ) - p=( ${p[@]%.*} ) - p=( $(compgen -W '${p[@]}' -- $cur ) ) - COMPREPLY=( ${COMPREPLY[@]} ${p[@]} ) - done -} -complete -F _man man - -_make() { - local i mk - local dir=. - local cur=${COMP_WORDS[COMP_CWORD]} - if [[ $cur = -* ]]; then - COMPREPLY=( $(compgen -W "-C -f" -- "$cur") ) - return 0 - fi - [[ $COMP_CWORD > 0 ]] && prev=${COMP_WORDS[COMP_CWORD-1]} - for (( i=1; i < ${#COMP_WORDS[@]}-1; i++ )); do - case ${COMP_WORDS[i]} in - -f) mk=${COMP_WORDS[i+1]} ;; - -C) dir=${COMP_WORDS[i+1]} ;; - esac - done - if [[ $prev = -C ]]; then - COMPREPLY=( $(compgen -d -- "$cur") ) - return 0 - fi - if [[ $prev = -f ]]; then - COMPREPLY=( $(cd $dir >/dev/null 2>&1; compgen -f -- "$cur") ) - return 0 - fi - mk=$dir/$mk - [[ -f $mk ]] || mk=$(eval echo $dir/[Mm]akefile) - [[ -f $mk ]] || return 1 - COMPREPLY=( $(compgen -W "$(sed -n -e '/^[[:alnum:]_-]*:/{s=^\([^:]*\):.*=\1=;p;}' $mk)" -- $cur) ) - return 0 -} -complete -F _make make gmake pmake - -_cygcheck() { - local opt - local cur=${COMP_WORDS[COMP_CWORD]} - case $COMP_CWORD in - 1) - case $cur in - -*) - COMPREPLY=( $(compgen -W "-v --verbose -h --help -V --version -c --check-setup -s --sysinfo - -k --keycheck -f --find-package -l --list-package -p --package-query" -- "$cur") ) - return 0 ;; - *) - COMPREPLY=( $(compgen -c -- "$cur") ) - return 0 ;; - esac - ;; - 2) - opt=${COMP_WORDS[1]} - case $opt in - -c|--check-setup|-l|--list-package) - pkgs=( /etc/setup/*.lst.gz ) - pkgs=( ${pkgs[@]##*/} ) - pkgs=( ${pkgs[@]%.lst.gz} ) - COMPREPLY=( $(compgen -W '${pkgs[@]}' -- $cur ) ) - return 0;; - esac - return 0;; - esac - return 0 -} -complete -F _cygcheck cygcheck.exe cygcheck - -# Use bash-completion, if available. +# Use system wide completion, if available. if [ -f /etc/bash_completion ]; then - # Under Cygwin bash completition start a long time. + # Under Cygwin bash completition take a long time for starting. if [ ! "$OSTYPE" = cygwin ]; then . /etc/bash_completion - else - # But load local completion anyway. - if [ -f ~/.bash_completion ]; then - . ~/.bash_completion - fi fi -fi -if [ -f $HOME/usr/etc/bash_completion ]; then +elif [ -f $HOME/usr/etc/bash_completion ]; then . $HOME/usr/etc/bash_completion fi +# Load local completions. +if [ -f ~/.bash_completion ]; then + . ~/.bash_completion +fi +if [ -d ~/.bash_completion.d ]; then + for f in ~/.bash_completion.d/* ~/.bash_completion.d/.*; do + . $f + done +fi +