# update-rc.d(8) completion -*- shell-script -*- # # Copyright (C) 2004 Servilio Afre Puentes proc _update_rc_d { var cur = '', prev = '', words = '', cword = '' _init_completion || return var sysvdir = '', services = '', options = '', valid_options = '' [[ -d /etc/rc.d/init.d ]] && set sysvdir = '/etc/rc.d/init.d' \ || set sysvdir = '/etc/init.d' set services = '( '$(printf '%s ' $sysvdir/!(README*|*.sh|$_backup_glob)) ) set services = '( '${services[@]#$sysvdir/} ) set options = '( '-f -n ) if [[ $cword -eq 1 || "$prev" == -* ]] { set valid_options = '( '$( \ tr " " "\n" <<<"${words[@]} ${options[@]}" \ | sed -ne "/$( sed "s/ /\\|/g" <<<"${options[@]}" )/p" \ | sort | uniq -u \ ) ) setglobal COMPREPLY = '( '$( compgen -W '${options[@]} ${services[@]}' \ -X '$( tr " " "|" <<<${words[@]} )' -- "$cur" ) ) } elif [[ "$prev" == ?($( tr " " "|" <<<${services[@]} )) ]] { setglobal COMPREPLY = '( '$( compgen -W 'remove defaults start stop' -- "$cur" ) ) } elif [[ "$prev" == defaults && "$cur" == [0-9] ]] { setglobal COMPREPLY = '( '0 1 2 3 4 5 6 7 8 9 ) } elif [[ "$prev" == defaults && "$cur" == [sk]?([0-9]) ]] { setglobal COMPREPLY = '( '0 1 2 3 4 5 6 7 8 9 ) } elif [[ "$prev" == defaults && -z "$cur" ]] { setglobal COMPREPLY = '( '0 1 2 3 4 5 6 7 8 9 s k ) } elif [[ "$prev" == ?(start|stop) ]] { if [[ "$cur" == [0-9] || -z "$cur" ]] { setglobal COMPREPLY = '( '0 1 2 3 4 5 6 7 8 9 ) } elif [[ "$cur" == [0-9][0-9] ]] { setglobal COMPREPLY = '( '$cur ) } else { setglobal COMPREPLY = ''() } } elif [[ "$prev" == ?([0-9][0-9]|[0-6S]) ]] { if [[ -z "$cur" ]] { if [[ $prev == [0-9][0-9] ]] { setglobal COMPREPLY = '( '0 1 2 3 4 5 6 S ) } else { setglobal COMPREPLY = '( '0 1 2 3 4 5 6 S . ) } } elif [[ "$cur" == [0-6S.] ]] { setglobal COMPREPLY = '( '$cur ) } else { setglobal COMPREPLY = ''() } } elif [[ "$prev" == "." ]] { setglobal COMPREPLY = '( '$( compgen -W "start stop" -- "$cur" ) ) } else { setglobal COMPREPLY = ''() } return 0 } && complete -F _update_rc_d update-rc.d # ex: ts=4 sw=4 et filetype=sh