Skip to content

Instantly share code, notes, and snippets.

@dayne
Last active April 21, 2017 16:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dayne/dde91c992771c4e590937a003dd39018 to your computer and use it in GitHub Desktop.
Save dayne/dde91c992771c4e590937a003dd39018 to your computer and use it in GitHub Desktop.
current knife block hint script
#!/bin/bash
if [ -d $HOME/.chef ]; then
cd $HOME/.chef
knife_target=$(readlink knife.rb)
current=$(basename -s .rb ${knife_target/knife-/})
echo -n $current
else
echo ""
fi

Simple script to give me the name of my current knife block target.

Used to provide that hint in my bash_it custom prompt kind of like so:

chef_knife_block() {
  if [ -f $HOME/.chef/knife.rb ]; then
     knife_target=$(readlink $HOME/.chef/knife.rb)
     echo "[$(basename -s .rb ${knife_target/knife-/})]"
  else
    echo ""
  fi
}
# fancy stuff for bashit
PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(chef_knife_block)$(modern_scm_prompt)[${cyan}\W${normal}][$(battery_charge)]$(is_vim_shell)
${bold_red}└─▪${normal} ${HOSTNAME%%.*} $ "

Results in giving me a bash propt with the following hint on my terminal prompt which knife block I'm pointing at:

┌─[home][~][]
└─▪ gibson > knife block n1nj4
The knife configuration has been updated to use n1nj4
┌─[n1nj4][~][]
└─▪ gibson >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment