-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.prompt
24 lines (19 loc) · 1.23 KB
/
.prompt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# .prompt
function __version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
# Better prompt w/ git integration
GIT_VERSION=$(git version 2>/dev/null | sed 's/.*git version \([0-9]*\.[0-9]*\).*/\1/')
if [ -z "$GIT_VERSION" ]; then
# git not installed or in the current path
export PS1='\[\033[0;35m\]\u@\h\[\033[0;33m\] \w\[\033[00m\] \[\033[37m\]$\[\033[00m\]: '
elif [ $(__version $GIT_VERSION) -lt $(__version "1.8") ]; then
# git 1.7 or below doesn't support git status --branch
export PS1='\[\033[0;35m\]\u@\h\[\033[0;33m\] \w\[\033[00m\]$(git describe --dirty=* --all --exact-match 2>/dev/null | sed -e "s/^.*\/\(.*\)$/ (\1)/") \[\033[37m\]$\[\033[00m\]: '
else
# git 1.8 or above
export PS1='\[\033[0;35m\]\u@\h\[\033[0;33m\] \w\[\033[00m\]$(git status --branch --ignore-submodules --porcelain --untracked-files=normal 2>/dev/null | sed -e '"'"'3,$d'"'"' -e '"'"'$!N;s/\\n.*/*/'"'"' -e '"'"'s/\\.\\.\\..* \\[ahead [0-9]*\\]/+/'"'"' -e '"'"'s/\\.\\.\\.[^*]*//'"'"' -e '"'"'s/^## \(.*\)/ (\1)/'"'"') \[\033[37m\]$\[\033[00m\]: '
fi
unset __version
# Export PROMPT_COMMAND only needed once
export PROMPT_COMMAND
# Set iTerm Window\Tab Title
PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME}: ${PWD/$HOME/~}\007"'