PageRenderTime 13ms CodeModel.GetById 11ms app.highlight 0ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 1# update-rc.d(8) completion
 2#
 3# Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
 4
 5
 6comp_include _get_cword
 7
 8
 9_update_rc_d()
10{
11    local cur prev sysvdir services options valid_options
12
13    cur=`_get_cword`
14    prev=${COMP_WORDS[COMP_CWORD-1]}
15
16    [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
17    || sysvdir=/etc/init.d
18
19    services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm*)) )
20    services=( ${services[@]#$sysvdir/} )
21    options=( -f -n )
22
23    if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then
24    valid_options=( $( \
25        echo "${COMP_WORDS[@]} ${options[@]}" \
26        | tr " " "\n" \
27        | sed -ne "/$( echo "${options[@]}" | sed "s/ /\\|/g" )/p" \
28        | sort | uniq -u \
29        ) )
30    COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \
31        -X '$( echo ${COMP_WORDS[@]} | tr " " "|" )' -- $cur ) )
32    elif [[ "$prev" == ?($( echo ${services[@]} | tr " " "|" )) ]]; then
33    COMPREPLY=( $( compgen -W 'remove defaults start stop' -- $cur ) )
34    elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then
35    COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
36    elif [[ "$prev" == defaults && "$cur" == [sk]?([0-9]) ]]; then
37    COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
38    elif [[ "$prev" == defaults && -z "$cur" ]]; then
39    COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 s k )
40    elif [[ "$prev" == ?(start|stop) ]]; then
41    if [[ "$cur" == [0-9] || -z "$cur" ]]; then 
42        COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
43    elif [[ "$cur" == [0-9][0-9] ]]; then 
44        COMPREPLY=( $cur )
45    else
46        COMPREPLY=()
47    fi
48    elif [[ "$prev" == ?([0-9][0-9]|[0-6S]) ]]; then
49    if [[ -z "$cur" ]]; then
50        if [[ $prev == [0-9][0-9] ]]; then
51        COMPREPLY=( 0 1 2 3 4 5 6 S )
52        else
53        COMPREPLY=( 0 1 2 3 4 5 6 S . )
54        fi
55    elif [[ "$cur" == [0-6S.] ]]; then 
56        COMPREPLY=( $cur )
57    else
58        COMPREPLY=()
59    fi
60    elif [[ "$prev" == "." ]]; then
61    COMPREPLY=( $(compgen -W "start stop" -- $cur) )
62    else
63    COMPREPLY=()
64    fi
65
66    return 0
67} # _update_rc_d()
68
69comp_install -F _update_rc_d  # Make completion persistent for subsequent invocations
70
71_update_rc_d  # Generate completions for first invocation