-
Notifications
You must be signed in to change notification settings - Fork 0
/
name_branch_bashrc.txt
30 lines (25 loc) · 1019 Bytes
/
name_branch_bashrc.txt
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
# uncomment or add this line
force_color_prompt=yes
# add some version of this text, changing the computer name and user name where appropriate, the section with if should already exist.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1="${debian_chroot:+($debian_chroot)}\[\033[01;33m\]nsryan@mac\[\033[00m\]:\[\033[01;32m\]\w\[\033[00m\]\$(parse_git_branch) $ "
else
PS1="${debian_chroot:+($debian_chroot)}nsryan2@mac:\w\$(parse_git_branch) $"
fi
unset color_prompt force_color_prompt
truncate_pwd() {
local dir=$(pwd)
local dir_parts
IFS='/' read -ra dir_parts <<< "$dir"
local dir_count=${#dir_parts[@]}
if [ "$dir_count" -le 4 ]; then
echo "$dir"
else
local truncated_dir=".../${dir_parts[-3]}/${dir_parts[-2]}/${dir_parts[-1]}"
echo "$truncated_dir"
fi
}
export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\$(truncate_pwd)\[\033[00m\]\$(parse_git_branch)\$ "