[chef] Knife bash completion


Chronological Thread 
  • From: Avishai Ish-Shalom < >
  • To:
  • Subject: [chef] Knife bash completion
  • Date: Wed, 19 Jan 2011 18:41:53 +0200
  • Organization: FewBytes Technologies

Attached is a bash completion script for knife. 1st level command
completion is fast (and hardcoded), nth level is read from `knife sub
command --help` so it's a little slow.

If anyone feels like adding feature, please do.

-- 
Regards,
Avishai Ish-Shalom

# vim: ft=sh:ts=4:sw=4:autoindent:
# Author: Avishai Ish-Shalom 
< >

# first argument set the command level
_get_knife_completions() {
        n=$1
        shift
        # first argument is knife, so shift it
        [ "$1" == "knife" ] && shift
        local opts
        opts="$(knife $@ --help | grep -E '^knife'|cut -f$n -d" ")"
        _upvar opts "$opts"
}
_knife() {
        local opts cur prev cword words
        opts="bootstrap client configure cookbook data ec2 exec index node 
rackspace recipe role search slicehost ssh status terremark windows"
        _get_comp_words_by_ref cur prev cword words
        COMPREPLY=()
        case $prev in
        upload)
                if [[ -n $CHEF_REPOS ]]; then
                        opts=$( ls -1p 

 | sort -u | sed -n 's/\/$//p' )
                        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
                fi
                ;;
        *)
                case $cword in
                1)
                        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
                        return 0
                        ;;
                *)
                        _get_knife_completions $(( $cword + 1 )) ${words[*]}
                        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
                        return 0
                        ;;
                esac
                ;;
        esac
        [[ 

 -ge 1 ]] && return 0
}
complete -F _knife knife
begin:vcard
fn:Avishai Ish-Shalom
n:Ish-Shalom;Avishai
org:FewBytes technologies
adr:;;7 Jabotinsky St.;Ramat-Gan;;52520;Israel
email;internet:
 
title:IT Consultant
tel;work:+972-3-5444-230 
tel;fax:+972-3-5444-720 
tel;cell:+972-54-4466499
note:skype: avishaiish
x-mozilla-html:TRUE
url:http://www.fewbytes.com/
version:2.1
end:vcard




Archive powered by MHonArc 2.6.16.

§