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)
|
|
|
|
# $
|
|
|
|
|
2017-05-22 17:26:35 +00:00
|
|
|
src_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
source $src_dir/colorize.sh
|
2017-05-22 17:02:46 +00:00
|
|
|
|
2017-05-23 22:59:53 +00:00
|
|
|
function sp_git {
|
2017-05-22 17:26:35 +00:00
|
|
|
# Get the current branch name
|
|
|
|
local git_branch=$(git branch 2>/dev/null | grep "*" | cut -d ' ' -f 2) || ""
|
|
|
|
|
2017-05-23 22:59:53 +00:00
|
|
|
# If we're in a git repo, add the repo (i.e. top-level directory) name, and parens
|
2017-05-22 17:26:35 +00:00
|
|
|
if [ "$git_branch" != "" ]; then
|
|
|
|
local git_repo=$(git rev-parse --show-toplevel)
|
2017-05-23 22:59:53 +00:00
|
|
|
git_repo=${git_repo//*\/}
|
|
|
|
echo "(${git_repo}|${git_branch})"
|
2017-05-22 17:26:35 +00:00
|
|
|
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
|
2017-05-23 22:59:53 +00:00
|
|
|
local path=${PWD//$git_dir/\!}
|
2017-05-22 17:02:46 +00:00
|
|
|
else
|
2017-05-23 22:59:53 +00:00
|
|
|
local path=${PWD//$HOME/\~}
|
2017-05-22 17:02:46 +00:00
|
|
|
fi
|
2017-05-23 22:59:53 +00:00
|
|
|
echo $path
|
2017-05-22 17:02:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 22:59:53 +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}"
|