forked from ronakg/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_prompt
85 lines (74 loc) · 1.95 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
#!/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="${cyan}\w${reset}"
_host="${italic}${orange}\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 "${yellow}(${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" != "rogandhi" ]]; then
user="${italic}$red\u${reset}${_sep}";
else
user="";
fi;
function 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="${blue}❯${reset} "
fi
PS1="\n${user}${_host}${_dir}\n${vim}$(find_virtualenv)$(find_git_branch)${ret_str}"
}
export PROMPT_COMMAND="history -a;history -c;history -r;prompt_command"
export PS2="${blue}.... ${reset}"