-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbash_powerline
executable file
·183 lines (149 loc) · 5.71 KB
/
bash_powerline
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env bash
# Borrowed and customized from https://github.com/riobard/bash-powerline
# and https://github.com/rmm5t/dotfiles/blob/master/bash_powerline
__powerline() {
# Unicode symbols
readonly PS_SYMBOL_DARWIN=''
# readonly PS_SYMBOL_LINUX='$'
readonly PS_SYMBOL_LINUX='🐧 '
readonly PS_SYMBOL_OTHER='%'
readonly GIT_BRANCH_SYMBOL='⑂'
readonly GIT_BRANCH_CHANGED_SYMBOL='+'
readonly GIT_NEED_PUSH_SYMBOL='⇡'
readonly GIT_NEED_PULL_SYMBOL='⇣'
readonly RUBY_SYMBOL='⬙'
readonly NODE_SYMBOL='⬢'
function __tput { tput $* 2> /dev/null; }
readonly FG_BLACK="\[$(__tput setaf 0)\]"
readonly FG_GRAY1="\[$(__tput setaf 15)\]"
readonly FG_GRAY2="\[$(__tput setaf 7)\]"
readonly FG_GRAY3="\[$(__tput setaf 8)\]"
readonly FG_RED="\[$(__tput setaf 9)\]"
readonly FG_GREEN="\[$(__tput setaf 10)\]"
readonly FG_YELLOW="\[$(__tput setaf 11)\]"
readonly FG_BLUE="\[$(__tput setaf 12)\]"
readonly FG_MAGENTA="\[$(__tput setaf 13)\]"
readonly FG_CYAN="\[$(__tput setaf 14)\]"
readonly FG_DARK_RED="\[$(__tput setaf 1)\]"
readonly FG_DARK_GREEN="\[$(__tput setaf 2)\]"
readonly FG_MUSTARD="\[$(__tput setaf 3)\]"
readonly FG_NAVY="\[$(__tput setaf 4)\]"
readonly FG_PURPLE="\[$(__tput setaf 5)\]"
readonly FG_TURQUOISE="\[$(__tput setaf 6)\]"
readonly BG_BLACK="\[$(__tput setab 0)\]"
readonly BG_GRAY1="\[$(__tput setab 15)\]"
readonly BG_GRAY2="\[$(__tput setab 7)\]"
readonly BG_GRAY3="\[$(__tput setab 8)\]"
readonly BG_RED="\[$(__tput setab 9)\]"
readonly BG_GREEN="\[$(__tput setab 10)\]"
readonly BG_YELLOW="\[$(__tput setab 11)\]"
readonly BG_BLUE="\[$(__tput setab 12)\]"
readonly BG_MAGENTA="\[$(__tput setab 13)\]"
readonly BG_CYAN="\[$(__tput setab 14)\]"
readonly BG_DARK_RED="\[$(__tput setab 1)\]"
readonly BG_DARK_GREEN="\[$(__tput setab 2)\]"
readonly BG_MUSTARD="\[$(__tput setab 3)\]"
readonly BG_NAVY="\[$(__tput setab 4)\]"
readonly BG_PURPLE="\[$(__tput setab 5)\]"
readonly BG_TURQUOISE="\[$(__tput setab 6)\]"
readonly BG_DEEP_GREEN="\[$(__tput setab 22)\]"
readonly DIM="\[$(__tput dim)\]"
readonly REVERSE="\[$(__tput rev)\]"
readonly RESET="\[$(__tput sgr0)\]"
readonly BOLD="\[$(__tput bold)\]"
# what OS?
case "$(uname)" in
Darwin)
readonly PS_SYMBOL=$PS_SYMBOL_DARWIN
;;
Linux)
readonly PS_SYMBOL=$PS_SYMBOL_LINUX
;;
*)
readonly PS_SYMBOL=$PS_SYMBOL_OTHER
esac
### Ruby #######################################################
if [ `which rvm 2> /dev/null` ]; then
__ruby_version() { printf $(~/.rvm/bin/rvm-prompt i v s g); }
elif [ `which ruby 2> /dev/null` ]; then
__ruby_version() { printf $(ruby --version | cut -d' ' -f2); }
else
__ruby_version() { return; }
fi
__ruby_info() {
local version=$(__ruby_version)
[ -z "${version}" ] && return
printf " $RUBY_SYMBOL ${version} "
}
### Node.js ####################################################
if [ `which nodenv 2> /dev/null` ]; then
__node_version() { printf $(nodenv version-name); }
elif [ `which node 2> /dev/null` ]; then
__node_version() { printf $(node -v | cut -d'v' -f2); }
node
__else_version() { return; }
fi
__node_info() {
local version=$(__node_version)
[ -z "${version}" ] && return
printf " $NODE_SYMBOL ${version} "
}
### Git ########################################################
__git_info() {
[ -x "$(which git)" ] || return # git not found
local git_eng="env LANG=C git" # force git output in English to make our work easier
# get current branch name or short SHA1 hash for detached head
local branch="$($git_eng symbolic-ref --short HEAD 2>/dev/null || $git_eng describe --tags --always 2>/dev/null)"
[ -n "$branch" ] || return # git branch not found
local marks
# branch is modified?
[ -n "$($git_eng status --porcelain)" ] && marks+=" $GIT_BRANCH_CHANGED_SYMBOL"
# how many commits local branch is ahead/behind of remote?
local stat="$($git_eng status --porcelain --branch | grep '^##' | grep -o '\[.\+\]$')"
local aheadN="$(echo $stat | grep -o 'ahead [[:digit:]]\+' | grep -o '[[:digit:]]\+')"
local behindN="$(echo $stat | grep -o 'behind [[:digit:]]\+' | grep -o '[[:digit:]]\+')"
[ -n "$aheadN" ] && marks+=" $GIT_NEED_PUSH_SYMBOL$aheadN"
[ -n "$behindN" ] && marks+=" $GIT_NEED_PULL_SYMBOL$behindN"
printf " $GIT_BRANCH_SYMBOL $branch$marks "
}
### AWS Profile ################################################
__aws_info() {
[ -z "${AWSUME_PROFILE}" ] && return
printf " AWS: ${AWSUME_PROFILE} "
}
# ### Kubernetes Info ############################################
# source /usr/local/share/kube-ps1.sh
# __kube_info() {
# printf " $(kube_ps1) "
# }
### PROMPT #####################################################
__title_info() { echo -ne "${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}"; }
case $TERM in
xterm*|rxvt|Eterm|eterm)
title() { echo -ne "\033]0;$(__title_info)\007"; }
;;
screen)
title() { echo -ne "\033_$(__title_info)\033\\"; }
;;
esac
ps1() {
# Check the exit code of the previous command and display different
# colors in the prompt accordingly.
if [ $? -eq 0 ]; then
local BG_EXIT="$BG_DARK_GREEN"
else
local BG_EXIT="$BG_RED"
fi
PS1="\n$BG_GRAY3$FG_GRAY1 \s $RESET"
PS1+="$BG_MUSTARD$FG_BLACK \w $RESET"
PS1+="$BG_DARK_RED$FG_GRAY1$(__ruby_info)$RESET"
PS1+="$BG_DEEP_GREEN$FG_GRAY1$(__node_info)$RESET"
PS1+="$BG_MAGENTA$FG_GRAY1$(__aws_info)$RESET"
PS1+="$BG_BLUE$FG_GRAY1$(__git_info)$RESET\n"
PS1+="$BG_GRAY2$FG_BLACK \u@\h $RESET"
PS1+="$BG_EXIT$FG_GRAY1 $PS_SYMBOL $RESET "
}
PROMPT_COMMAND="ps1 && title"
}
__powerline
unset __powerline