31 lines
933 B
Bash
31 lines
933 B
Bash
# 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
|
|
|
|
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 {
|
|
local git_dir=$(git rev-parse --show-toplevel 2>/dev/null)
|
|
if [ "$git_dir" != "" ]; then
|
|
local path=${PWD//$git_dir/\!}
|
|
else
|
|
local path=${PWD//$HOME/\~}
|
|
fi
|
|
echo $path
|
|
}
|
|
|
|
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}"
|