-
Notifications
You must be signed in to change notification settings - Fork 495
/
Copy path10_powerline_go.sh
41 lines (36 loc) · 1.13 KB
/
10_powerline_go.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
if [[ "$(which powerline-go)" ]]; then
# Installed by homebrew on MacOS
powerline_go_cmd=powerline-go
elif [[ -x ${GOPATH:-~/go}/bin/powerline-go ]]; then
# Installed manually (for now) via
# go get -u github.com/justjanne/powerline-go
powerline_go_cmd=${GOPATH:-~/go}/bin/powerline-go
else
return
fi
function _update_ps1() {
PS1="$($powerline_go_cmd \
-static-prompt-indicator \
-cwd-mode plain \
-numeric-exit-codes \
-error $? \
-modules termtitle,time,venv,user,ssh,cwd,perms,git,hg,jobs,newline,exit,root \
)"
}
# Ensure exit code is reset when pressing "enter" with no command
# because I'm OCD.
__prompt_stack=()
trap '__prompt_stack=("${__prompt_stack[@]}" "$BASH_COMMAND")' DEBUG
function __prompt_exit_code() {
local exit_code=$?
# If the first command in the stack is __prompt_command, no command was run.
# Set exit_code to 0.
[[ "${__prompt_stack[0]}" == "__prompt_exit_code" ]] && exit_code=0
# Return the (correct) exit code.
return $exit_code
}
function __prompt_cleanup() {
# Reset the stack.
__prompt_stack=()
}
PROMPT_COMMAND='__prompt_exit_code;_update_ps1;__prompt_cleanup'