Skip to content

Instantly share code, notes, and snippets.

@shmatov
Last active January 20, 2020 10:49
Show Gist options
  • Save shmatov/3508983 to your computer and use it in GitHub Desktop.
Save shmatov/3508983 to your computer and use it in GitHub Desktop.
Bash prompt with rvm, nvm, virtualenv and git integration.
function __git_dirty {
git diff --quiet HEAD &>/dev/null
[ $? == 1 ] && echo " ↺ "
}
function __git_branch {
__git_ps1 "%s"
}
function __my_rvm_ruby_version {
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
[ "$gemset" != "" ] && gemset="@$gemset"
local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
local full="$version$gemset"
[ "$full" != "" ] && echo "rb:$full"
}
function __virtualenv {
local env=$(basename "$VIRTUAL_ENV")
[ "$env" != "" ] && echo "py:$env"
}
function __node {
if hash node 2>/dev/null; then
local v=$(node -v)
fi
[ "$v" != "" ] && echo "n:${v:1}"
}
function __info {
local full=(
$(__my_rvm_ruby_version)
$(__virtualenv)
$(__node)
$(__git_branch)
$(__git_dirty)
)
full="${full[*]}"
[ "$full" != "" ] && echo "[$full]"
}
PS1="┌─\$(__info)──(\w)\n└─>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment