forked from cowboy/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
prompt.sh
executable file
·43 lines (40 loc) · 1.28 KB
/
prompt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# this reconciles a conflict between the iterm integration script and having a custom prompt
if [[ `uname 2> /dev/null` =~ ^[Dd]arwin && "$TERM" != "screen" ]]; then
ps1_var=orig_ps1
elif [[ `uname 2> /dev/null` =~ ^[Ll]inux && $SESSION_TYPE == remote/ssh && "$TERM" != "screen" ]]; then
ps1_var=orig_ps1
else
ps1_var=PS1
fi
_prompt() { # [BN]
_trim_branch_name() { # [BN]
local max_length=${MAX_BRANCH_NAME_LENGTH:-25}
local branch_name="$1"
if [[ ${#branch_name} -gt $max_length ]]; then
branch_name="${branch_name:0:$((${max_length}-3))}..."
fi
echo "$branch_name"
}
local branch commit
if [[ -n `svnr 2> /dev/null` ]]; then
branch="`svnb`"
commit="`svnr`"
elif [[ -n `git log 2> /dev/null` ]]; then
branch="`git branch --no-color | egrep '^\*' | sed 's/^..//'`"
fi
if [[ -n $branch ]]; then
echo -n "${BOLD}[${FBLUE}`_trim_branch_name "${branch}"`${RES}"
if [[ -n $commit ]]; then
echo -n "${BOLD}:${FCYAN}${commit}${RES}"
fi
echo -n "${BOLD}]"
fi
echo "${BOLD}${FGREEN}\h${RES}${BOLD}:${FYELLOW}\w${RES}\n\$ "
unset _trim_branch_name
}
export prompt="export $ps1_var=\$(_prompt);"
# make sure there's only one copy of the prompt code
export PROMPT_COMMAND="${prompt}`echo "${PROMPT_COMMAND}" | sed "s|$prompt||g"`"
# clean up
unset ps1_var
unset escaped_prompt