knife bash completion – with fixed environments autocomplete

[Steven Danna](https://github.com/stevendanna/knife-hacks) has written the best `knife` bash completion script that I’ve seen for use with managing chef servers and the chef software by opscode.

Update: Steven has now made an update so this is working!

There was always one little thing wrong with it though:

> knife environment edit (etc) would not autocomplete – it would give an error

The error was:

-bash: _chef_environments: command not found

The solution is pretty simple – you just need to edit the script and transpose two letters that were a typo from the [knife_completion.sh](https://github.com/stevendanna/knife-hacks/blob/master/shell/knife_completion.sh) file:

_chef_environemnts

should actually be:

_chef_environments

The difference is hard to spot but it’s key.

Two other scripts for knife completion (that I don’t like as much) are [this one by avishai-ish-shalom](https://gist.github.com/avishai-ish-shalom/1050685) and [a spinoff by vindimy](https://github.com/vindimy/dotfiles/blob/master/bash-completion/knife.sh) – I think they are slower and not as user friendly.

If you use `zsh` instead of `bash` there is also a [zsh knife](https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/knife) plugin which is part of `oh-my-zsh` that seems pretty good.

Related Posts:

  • No Related Posts
This entry was posted in Server Administration, Tech Tips and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *