-
Notifications
You must be signed in to change notification settings - Fork 0
/
.ps1
139 lines (108 loc) · 2.46 KB
/
.ps1
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
#!/bin/bash
#Prompt and prompt colors
# 30m - Black
# 31m - Red
# 32m - Green
# 33m - Yellow
# 34m - Blue
# 35m - Purple
# 36m - Cyan
# 37m - White
# 0 - Normal
# 1 - Bold
BLUE="\[\e[0;34m\]"
CYAN="\[\e[0;36m\]"
GREEN="\[\e[0;32m\]"
PURPLE="\[\e[0;35m\]"
RED="\[\e[0;31m\]"
YELLOW="\[\e[0;33m\]"
CLR_END="\[\e[m\]"
case "$(whoami)" in
vagrant)
user_host_color="${YELLOW}"
cwd_color="${RED}"
prompt_color="${CYAN}"
git_color="${GREEN}"
;;
root)
user_host_color="${RED}"
cwd_color="${RED}"
prompt_color="${RED}"
git_color="${RED}"
;;
*)
user_host_color="${CYAN}"
cwd_color="${YELLOW}"
prompt_color="${RED}"
git_color="${GREEN}"
esac
source ~/.git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true # unstaged (*) and staged (+)
GIT_PS1_SHOWUNTRACKEDFILES=true # untracked files (%)
GIT_PS1_SHOWUPSTREAM="auto" # (<) behind, (>) ahead, (<>) diverged, (=) no difference
__prompt() {
local string=$1
local color=$2
if [ -z "${color}" ]; then
PS1+="${string}"
else
PS1+="${color}${string}${CLR_END}"
fi
}
__prompt_command() {
local EXIT="$?"
PS1=""
__prompt "\n"
if [ $EXIT != 0 ]; then
EXIT_COLOR="${RED}"
else
EXIT_COLOR="${GREEN}"
fi
__prompt "[${EXIT}]" "${EXIT_COLOR}"
__prompt " "
# show how long the last command took to run
__prompt "\${timer_show}" "${BLUE}"
__prompt " "
# YYYY-MM-DD HH:MM:SS
__prompt "\D{%F %T}"
__prompt " "
# username and host
__prompt "\u@\h " "${user_host_color}"
# cwd
__prompt "\n "
__prompt "\w" "${cwd_color}"
# GIT
__prompt "\$(__git_ps1)" "${git_color}"
__prompt "\n "
# conda env normally shows up at beginning of prompt, but must be handled
# here when setting PROMPT_COMMAND
if [ ! -z "${CONDA_DEFAULT_ENV}" ]; then
__prompt "(${CONDA_DEFAULT_ENV}) " "${PURPLE}"
fi
# virtualenv
if [ ! -z "${VIRTUAL_ENV}" ]; then
__prompt "($(basename ${VIRTUAL_ENV})) " "${PURPLE}"
fi
__prompt "> " "${RED}"
}
function timer_result() {
((h=${1}/3600))
((m=(${1}%3600)/60))
((s=${1}%60))
if [ "${m}" = "0" ] && [ "${h}" = "0" ]; then
printf "(%02d)" $s
elif [ "${h}" = "0" ]; then
printf "(%02d:%02d)" $m $s
else
printf "(%02d:%02d:%02d)" $h $m $s
fi
}
function timer_start {
timer=${timer:-$SECONDS}
}
function timer_stop {
timer_show=$(timer_result $(($SECONDS - $timer)))
unset timer
}
trap 'timer_start' DEBUG
PROMPT_COMMAND="__prompt_command; timer_stop"