Hi, Here is a small bash completion function that lists existing runlevels. It's almost nothing, but I think it eases usage of /sbin/rc and /bin/rc-status, hence I suggest its inclusion in /etc/bash_completion.d/gentoo: # # rc & rc-status completion command # _runlevels() { local cur runlvdir origdir origdir=${PWD} runlvdir=/etc/runlevels COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} if [ ${#COMP_WORDS[*]} -le 2 ]; then cd ${runlvdir} COMPREPLY=( $( compgen -G "${cur}*" ) ) cd ${origdir} fi return 0 } complete -F _runlevels rc rc-status
rc-status doesn't seem to care about the runlevel argument: joker@milka ~ $ rc-status nonetwork Runlevel: default atd [ started ] dcron [ started ] It always outputs "default". The completion for "rc" is fine. But rc-status also supports arguments. And completion should also complete those arguments like with other commands.
Strange, it works for me: rc-status displays the status of services for the right runlevel, the one I ask on command line. I'm using baselayout-1.8.6.12, maybe it is your version that has a bug? That said, I've just realized that it also support a few options other than the runlevel name, so I will write a different completion function for it.
Would this be ok? It completes the rc-status options too. # # rc & rc-status completion command # _rc() { local cur COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} if [ ${#COMP_WORDS[*]} -le 2 ]; then COMPREPLY=( $( compgen -W "$(for i in /etc/runlevels/*; do echo ${i##*/}; done)" | grep ^$cur ) ) fi return 0 } complete -F _rc rc _rc-status() { local cur opts COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} if [ ${#COMP_WORDS[*]} -le 2 ]; then opts="-a -all -l --list -u --unused" COMPREPLY=( $( compgen -W "${opts} $(for i in /etc/runlevels/*; do echo ${i##*/}; done) " | grep ^$cur ) ) fi return 0 } complete -F _rc-status rc-status
" -- $cur" ofcourse ... not "| grep ^$cur"
Yes it would be okay. I had not seen your reply at first so I had also written my version, which does just about the same. The only difference is that I only display the options list when the arg begin with a "-", but show only runlevels otherwise.: # # /sbin/rc completion command # _runlevels() { local cur numwords runlvdir origdir origdir=${PWD} runlvdir=/etc/runlevels COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} if [ ${#COMP_WORDS[*]} -le 2 ]; then cd ${runlvdir} COMPREPLY=( $( compgen -G "${cur}*" ) ) cd ${origdir} fi return 0 } complete -F _runlevels rc # # /bin/rc-status completion command # _rcstatus() { local cur numwords runlvdir origdir options origdir=${PWD} runlvdir=/etc/runlevels COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} if [ ${#COMP_WORDS[*]} -le 2 ]; then if [[ "$cur" == -* ]]; then options="--all --list --unused" COMPREPLY=( $( compgen -W "$options" -- $cur ) ) else cd ${runlvdir} COMPREPLY=( $( compgen -G "${cur}*" ) ) cd ${origdir} fi fi return 0 } complete -F _rcstatus rc-status I let you decide what you prefer, I don't really care :)
Added bash-completion-20031125-r1 to cvs with KEYWORDS ~arch.