/bash_completion_lib/complete/update-rc.d!
http://github.com/brinkman83/bashrc · Unknown · 71 lines · 60 code · 11 blank · 0 comment · 0 complexity · 4b43917c6e2af7bcb1bd37507c611945 MD5 · raw file
- # update-rc.d(8) completion
- #
- # Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
- comp_include _get_cword
- _update_rc_d()
- {
- local cur prev sysvdir services options valid_options
- cur=`_get_cword`
- prev=${COMP_WORDS[COMP_CWORD-1]}
- [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
- || sysvdir=/etc/init.d
- services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm*)) )
- services=( ${services[@]#$sysvdir/} )
- options=( -f -n )
- if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then
- valid_options=( $( \
- echo "${COMP_WORDS[@]} ${options[@]}" \
- | tr " " "\n" \
- | sed -ne "/$( echo "${options[@]}" | sed "s/ /\\|/g" )/p" \
- | sort | uniq -u \
- ) )
- COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \
- -X '$( echo ${COMP_WORDS[@]} | tr " " "|" )' -- $cur ) )
- elif [[ "$prev" == ?($( echo ${services[@]} | tr " " "|" )) ]]; then
- COMPREPLY=( $( compgen -W 'remove defaults start stop' -- $cur ) )
- elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then
- COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
- elif [[ "$prev" == defaults && "$cur" == [sk]?([0-9]) ]]; then
- COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
- elif [[ "$prev" == defaults && -z "$cur" ]]; then
- COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 s k )
- elif [[ "$prev" == ?(start|stop) ]]; then
- if [[ "$cur" == [0-9] || -z "$cur" ]]; then
- COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
- elif [[ "$cur" == [0-9][0-9] ]]; then
- COMPREPLY=( $cur )
- else
- COMPREPLY=()
- fi
- elif [[ "$prev" == ?([0-9][0-9]|[0-6S]) ]]; then
- if [[ -z "$cur" ]]; then
- if [[ $prev == [0-9][0-9] ]]; then
- COMPREPLY=( 0 1 2 3 4 5 6 S )
- else
- COMPREPLY=( 0 1 2 3 4 5 6 S . )
- fi
- elif [[ "$cur" == [0-6S.] ]]; then
- COMPREPLY=( $cur )
- else
- COMPREPLY=()
- fi
- elif [[ "$prev" == "." ]]; then
- COMPREPLY=( $(compgen -W "start stop" -- $cur) )
- else
- COMPREPLY=()
- fi
- return 0
- } # _update_rc_d()
- comp_install -F _update_rc_d # Make completion persistent for subsequent invocations
- _update_rc_d # Generate completions for first invocation