Skip to content

Instantly share code, notes, and snippets.

@coryf
Created November 30, 2011 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coryf/1411266 to your computer and use it in GitHub Desktop.
Save coryf/1411266 to your computer and use it in GitHub Desktop.
Cory's Prompt
Green="\033[0;32m"
Yellow="\033[0;33m"
Blue="\033[0;34m"
Red="\033[0;31m"
GreyB="\033[1;30m"
Normal="\033[0m"
smiley() {
ret_val=$?
if [ "$ret_val" = "0" ]
then
echo -e "$Green:)"
else
echo -e "$Red:($ret_val)"
fi
}
function directory_to_titlebar {
local last_ret=$?
local pwd_length=25 # The maximum length
local dir="$PWD"
# Substitute a leading path that's in $HOME for "~"
if [[ "$HOME" == ${dir:0:${#HOME}} ]] ; then
dir="~${dir:${#HOME}}"
fi
# Append a trailing slash if it's not there already.
if [[ ${dir:${#dir}-1} != "/" ]] ; then
dir="$dir/"
fi
# Truncate if we're too long.
# We preserve the leading '/' or '~/', and substitute
# ellipses for some directories in the middle.
if [[ "$dir" =~ (~){0,1}/.*(.{${pwd_length}}) ]] ; then
local tilde=${BASH_REMATCH[1]}
local directory=${BASH_REMATCH[2]}
# At this point, $directory is the truncated end-section of the
# path. We will now make it only contain full directory names
# (e.g. "ibrary/Mail" -> "/Mail").
if [[ "$directory" =~ [^/]*(.*) ]] ; then
directory=${BASH_REMATCH[1]}
fi
dir="$tilde/...$directory"
fi
echo -e "$dir"
#passthrough return val
return $last_ret
}
GIT_PS1_SHOWDIRTYSTATE=1 #... untagged(*) and staged(+) changes
GIT_PS1_SHOWSTASHSTATE=1 #... if something is stashed($)
GIT_PS1_SHOWUNTRACKEDFILES=1 #... untracked files(%)
GIT_PS1_SHOWUPSTREAM="auto verbose"
PS1="\[\e]2;\h:\]\$PWD\[\a\]\[\e]1;\]\$(directory_to_titlebar)\[\a\]\[$Green\]\u@\h\[$Normal\]:\[$Blue\]\w \$(smiley) \[$Yellow\]\$(__git_ps1 \"(%s)\")\[$GreyB\]\n$ \[$Normal\]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment