rc.d bash completion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



i wrote a very simple rc.d bash completion script. is there any chance
it can be used upstream?

the script is uploaded to http://paste.pocoo.org/show/391283/

it is also copy-pasted here for your convenience:

#!/bin/bash

_rc.d_getdaemons ()
{
    /usr/bin/find "$1" -mindepth 1 -maxdepth 1 -type f -printf '%f\n'
}

_rc.d_arraydiff ()
{
    local arr
    declare -A arr

    for elem in "${!1}"
    do
        arr[$elem]=1
    done
    for elem in "${!2}"
    do
        unset arr[$elem]
    done
    echo "${!arr[@]}"
}

_rc.d ()
{
    local command commands available started
    local cur words cword

    commands="list help start stop restart"
    available=($(_rc.d_getdaemons /etc/rc.d))
    started=($(_rc.d_getdaemons /run/daemons))

    _get_comp_words_by_ref -n =: cur words cword
    [ $cword -gt 1 ] && command=${words[1]}

    if [ -z "$command" ]
    then
        COMPREPLY=($(compgen -W "$commands" -- $cur))
    else
        case "$command" in
            start)
                COMPREPLY=($(compgen -W "$(_rc.d_arraydiff \
                    available[@] started[@])" -- $cur))
                ;;
            stop|restart)
                COMPREPLY=($(compgen -W "$(echo ${started[@]})" -- $cur))
                ;;
            list|help|*)
                COMPREPLY=()
                ;;
        esac
    fi
}

complete -F _rc.d rc.d


[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux