Skip to content

Instantly share code, notes, and snippets.

@kamataryo
Last active July 4, 2016 16:23
Show Gist options
  • Save kamataryo/9ffd349ef806d5cdbc6b48949a853b63 to your computer and use it in GitHub Desktop.
Save kamataryo/9ffd349ef806d5cdbc6b48949a853b63 to your computer and use it in GitHub Desktop.
bash/zsh prompt support to check if Vagrantfile exists.
# Add or custome for your .bashrc
source ~/.vagrant-prompt.sh
export PS1='\u@\h \W\[\033[33m\]$(__vagrant_pt)\[\033[00m\] $ '
#!/bin/sh
# bash/szh vagrant prompt support
__vagrant_pt(){
dirname=$(pwd)
# prevent to trap while, when you are on not-existing dir
if [[ ! -d $dirname ]]; then
return
fi
if [[ -e "$dirname/Vagrantfile" ]]; then
echo "[vm]"
else
while [ "$dirname" != "/" ]
do
dirname=$(cd $dirname/..;pwd)
if [[ -e $dirname/Vagrantfile ]]; then
echo "[>vm]"
break
fi
done
fi
}
# Add or custome for your .zshrc
setopt PROMPT_SUBST
source ~/.vagrant-prompt.sh
export PS1='%n@%m %c%F{yellow}$(__vagrant_pt)%f \$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment