config/bash/super_prompt.sh

31 lines
933 B
Bash
Raw Normal View History

2017-05-22 17:02:46 +00:00
# Produces a nice, colorful 2-line prompt of the form:
# [username@hostname:current_directory] (git_repo|branch)
# $
src_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $src_dir/colorize.sh
2017-05-22 17:02:46 +00:00
function sp_git {
# Get the current branch name
local git_branch=$(git branch 2>/dev/null | grep "*" | cut -d ' ' -f 2) || ""
# If we're in a git repo, add the repo (i.e. top-level directory) name, and parens
if [ "$git_branch" != "" ]; then
local git_repo=$(git rev-parse --show-toplevel)
git_repo=${git_repo//*\/}
echo "(${git_repo}|${git_branch})"
fi
}
function sp_path {
2017-05-22 17:02:46 +00:00
local git_dir=$(git rev-parse --show-toplevel 2>/dev/null)
if [ "$git_dir" != "" ]; then
local path=${PWD//$git_dir/\!}
2017-05-22 17:02:46 +00:00
else
local path=${PWD//$HOME/\~}
2017-05-22 17:02:46 +00:00
fi
echo $path
2017-05-22 17:02:46 +00:00
}
export PS1="[${C_YELLOW}\u${C_NO}@${C_BLUE}${HOSTNAME}${C_NO}:${C_GREEN}\$(sp_path)${C_NO}] ${C_MAGENTA}\$(sp_git)${C_NO}\n${C_RED}\$ ${C_NO}"