-
Notifications
You must be signed in to change notification settings - Fork 8
/
bash_prompt
100 lines (86 loc) · 2.24 KB
/
bash_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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env bash
if tput setaf 1 &> /dev/null; then
tput sgr0; # reset colors
bold="\[$(tput bold)\]";
italic="\[$(tput sitm)\]";
reset="\[$(tput sgr0)\]";
purple="\[$(tput setaf 5)\]"
black="\[$(tput setaf 0)\]"
red="\[$(tput setaf 1)\]"
green="\[$(tput setaf 2)\]"
yellow="\[$(tput setaf 3)\]"
blue="\[$(tput setaf 4)\]"
magenta="\[$(tput setaf 5)\]"
cyan="\[$(tput setaf 6)\]"
white="\[$(tput setaf 7)\]"
orange="\[$(tput setaf 166)\]"
gray="\[$(tput setaf 246)\]"
fi;
_sep="${gray} \[•\] ${reset}"
_dir="${red}\w${reset}"
_host="${italic}${blue}\H${reset}${_sep}";
find_git_branch() {
# Based on: http://stackoverflow.com/a/13003854/170413
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached*'
fi
echo "${green}(${branch})${reset} "
else
echo ""
fi
}
find_git_dirty() {
local status=$(git status --porcelain 2> /dev/null)
if [[ "$status" != "" ]]; then
echo '*'
else
echo ''
fi
}
# Determine active Python virtualenv details.
find_virtualenv() {
if test -z "$VIRTUAL_ENV" ; then
echo ""
else
echo "$cyan[`basename \"$VIRTUAL_ENV\"`] "
fi
}
# Highlight the user name when logged in as root.
USER=$(whoami)
if [[ "$USER" == "root" ]]; then
user="${italic}${bold}$red\u${reset}${_sep}";
else
user="$yellow\u${reset}${_sep}";
fi;
prompt_command() {
ret_code=$?
# Are we running in a shell invoked from Vim?
if [[ "$VIM" ]]; then
vim="${red}(Vim)${reset} "
else
vim=""
fi
# Did last command return non-zero value?
if [ "${ret_code}" != 0 ]; then
ret_str="${red}❯❯${reset} "
else
ret_str="${green}❯${reset} "
fi
PS1="\n${user}${_host}${_dir}\n${vim}$(find_virtualenv)$(find_git_branch)${ret_str}"
}
HISTSIZE=9000
HISTFILESIZE=$HISTSIZE
_bash_history_sync() {
builtin history -a #1
HISTFILESIZE=$HISTSIZE #2
#builtin history -c #3
#builtin history -r #4
}
history() { #5
_bash_history_sync
builtin history "$@"
}
export PROMPT_COMMAND="prompt_command; _bash_history_sync"
export PS2="${blue}.... ${reset}"