Add new, better prompt.

This commit is contained in:
Anna Wiggins 2017-05-22 10:02:46 -07:00
parent bbf54dd05f
commit 2e218bdc0a
No known key found for this signature in database
GPG key ID: 682893DD0448ED78
3 changed files with 55 additions and 18 deletions

29
bash/super_prompt.sh Normal file
View file

@ -0,0 +1,29 @@
# Produces a nice, colorful 2-line prompt of the form:
# [username@hostname:current_directory] (git_repo|branch)
# $
source ./colorize.sh
function super_prompt {
local git_dir=$(git rev-parse --show-toplevel 2>/dev/null)
if [ "$git_dir" != "" ]; then
local path=$(colorize green ${PWD//$git_dir/\!})
else
local path=$(colorize green ${PWD//$HOME/\~})
fi
local git_branch=$(git branch 2>/dev/null | grep "*" | cut -d ' ' -f 2) || ""
if [ "$git_branch" != "" ]; then
local git_repo=$(git rev-parse --show-toplevel)
git_branch=\($(colorize magenta ${git_repo//*\/})"|"$(colorize magenta ${git_branch})\)
fi
local user=$(colorize yellow $(whoami))
local host=$(colorize blue ${HOSTNAME})
local prompt_char=$(colorize red '$')
prompt=$(printf "[%s@%s:%s] %s\n\f\r%s " "$user" "$host" "$path" "$git_branch" "$prompt_char")
echo $prompt
}
# export PS1=super_prompt