Bash completion für Dell OMSA

Aus Bennys Wiki
Wechseln zu: Navigation, Suche

Bash completion für Dell OpenManage Server Administrator[Bearbeiten]

Nachfolgenden Codeschnipsel nach der Installation des Packets bash-completion und ggf der Aktivierung in der /etc/bash.bashrc unter dem Namen

vim /etc/bash_completion.d/dell_omsa

speichern.

# omreport completion
# 2008-09-22 Benny
# quick and dirty hack for omreport and omconfig

have omreport &&
_omreport()
{
        local cur conns

        [ -x /usr/bin/omreport ] || return 0

        COMPREPLY=()
        cur=${COMP_WORDS[COMP_CWORD]}

        if [ $COMP_CWORD -eq 1 ]; then
                conns=$(\omreport -? |awk 'BEGIN { FS="[[:space:]+]"; x=0; print_lines=0; found_cmd=0 } x=x+1 { if ( $1 ~ /^Command/ ) { print_lines=1; found_cmd=x } if ( print_lines==1 && NF == 0 && $1 ~ /^$/ ) { print_lines=0 } if (print_lines == 1 && x > found_cmd && $1 ~ /^[A-Za-z0-9]/) { print $1 } }' )
        elif [ $COMP_CWORD -eq 2 ]; then
                conns=$(\omreport ${COMP_WORDS[1]} -? |awk 'BEGIN { FS="[[:space:]+]"; x=0; print_lines=0; found_cmd=0 } x=x+1 { if ( $1 ~ /^Command/ ) { print_lines=1; found_cmd=x } if ( print_lines==1 && NF == 0 && $1 ~ /^$/ ) { print_lines=0 } if (print_lines == 1 && x > found_cmd && $1 ~ /^[A-Za-z0-9]/) { print $1 } }' )
        fi
        COMPREPLY=( $(compgen -W "${conns}" "${cur}") )

        return 0
}
[ "$have" ] && complete -F _omreport omreport

have omconfig &&
_omconfig()
{
        local cur conns

        [ -x /usr/bin/omconfig ] || return 0

        COMPREPLY=()
        cur=${COMP_WORDS[COMP_CWORD]}

        if [ $COMP_CWORD -eq 1 ]; then
                conns=$(\omconfig -? |awk 'BEGIN { FS="[[:space:]+]"; x=0; print_lines=0; found_cmd=0 } x=x+1 { if ( $1 ~ /^Command/ ) { print_lines=1; found_cmd=x } if ( print_lines==1 && NF == 0 && $1 ~ /^$/ ) { print_lines=0 } if (print_lines == 1 && x > found_cmd && $1 ~ /^[A-Za-z0-9]/) { print $1 } }' )
        elif [ $COMP_CWORD -eq 2 ]; then
                conns=$(\omconfig ${COMP_WORDS[1]} -? |awk 'BEGIN { FS="[[:space:]+]"; x=0; print_lines=0; found_cmd=0 } x=x+1 { if ( $1 ~ /^Command/ ) { print_lines=1; found_cmd=x } if ( print_lines==1 && NF == 0 && $1 ~ /^$/ ) { print_lines=0 } if (print_lines == 1 && x > found_cmd && $1 ~ /^[A-Za-z0-9]/) { print $1 } }' )
        fi
        COMPREPLY=( $(compgen -W "${conns}" "${cur}") )

        return 0
}
[ "$have" ] && complete -F _omconfig omconfig