Skip to content

Instantly share code, notes, and snippets.

@CoffeeAndCode
Last active December 10, 2015 19:08
Show Gist options
  • Save CoffeeAndCode/4478878 to your computer and use it in GitHub Desktop.
Save CoffeeAndCode/4478878 to your computer and use it in GitHub Desktop.
Show if a Vagrant server is "on" or "off" in the command prompt if in a folder with a Vagrantfile. Code for http://jonknapp.com/2013/01/vagrant-status-in-the-command-line/
#
# Colors
#
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NORMAL="\[\033[0m\]"
DARK_PURPLE="\[\033[1;34m\]"
#
# Prompt Setup
#
function parse_git_in_rebase {
[[ -d .git/rebase-apply ]] && echo " REBASING"
}
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
}
function parse_git_branch {
branch=$(git branch 2> /dev/null | grep "*" | sed -e s/^..//g)
if [[ -z ${branch} ]]; then
return
fi
echo "("${branch}$(parse_git_dirty)$(parse_git_in_rebase)")"
}
function parse_vagrant_status {
status=`vagrant status 2>&1`
if [[ -n `echo ${status} | grep "poweroff"` ]]; then
echo "[off]"
fi
if [[ -n `echo ${status} | grep "running"` ]]; then
echo "[on]"
fi
if [[ -n `echo ${status} | grep "aborted"` ]]; then
echo "[aborted]"
fi
return
}
# Prompt with git and vagrant status
export PS1="$RED\u@\h:$GREEN\W\n$DARK_PURPLE\$(parse_vagrant_status)$YELLOW\$(parse_git_branch)$NORMAL\$ "
@CoffeeAndCode
Copy link
Author

added "aborted" status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment