-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfish_prompt.fish
176 lines (153 loc) · 5.54 KB
/
fish_prompt.fish
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
function fish_prompt --description 'Write out the prompt'
set -l last_status $status
# detailed prompt
if test -n "$fish_prompt_detailed" && test "$TERM_PROGRAM" != "vscode"
if not test -n "$fish_prompt_detailed_last_check"
set -U fish_prompt_detailed_last_check (date +%s)
end
# reload environment in every X minutes (fish_prompt_detailed_reload_interval, default=600 sec=10 min) or in case of `chenv`
set -q fish_prompt_detailed_reload_interval || set -xU fish_prompt_detailed_reload_interval 600
# update prompt values
if test (date +%s) -gt (math "$fish_prompt_detailed_last_check + $fish_prompt_detailed_reload_interval") || test $fish_prompt_detailed_reset -eq 1
set -U fish_prompt_detailed_last_check (date +%s)
set_color -b magenta -i
echo -n " Reload NVM, R53, GCP and K8S configs "
set_color normal
echo
set -xU GOOGLE_CONFIG (gcloud config configurations list --filter 'is_active=true' --format 'value(name)')
set -xU GOOGLE_PROJECT (gcloud config configurations list --filter 'is_active=true' --format 'value(properties.core.project)')
set -xU K8S_CLUSTER (kubectl config current-context 2>&1)
# if test $fish_detailed_prompt_reset -eq 0
# chenv reset
# end
if test $K8S_CLUSTER != "error: current-context is not set"
set -xU K8S_CLUSTER_VERSION (kubectl version --short | awk '/Server/{print$3}')
else
set -xU K8S_CLUSTER_VERSION "n/a"
set -xU K8S_CLUSTER_SHORT ''
end
set -U fish_prompt_detailed_reset 0
if test -n "$TERM_PROGRAM"
if test "$TERM_PROGRAM" = "iTerm.app"
iterm2_update_user_vars
end
end
end
# node/npm version
if test -z "$NVM_BIN"
if test (which nvm) || test (functions --details nvm)
nvm use default
set -xU NVM_CURRENT_VERSION ($NVM_BIN/node -v)'/'($NVM_BIN/npm -v)
else
echo "'nvm' is not installed."
if not test (which node)
echo "'node' is not installed."
else
set -xU NVM_CURRENT_VERSION (node -v)'/'(npm -v)
end
end
else
set -xU NVM_CURRENT_VERSION (node -v)'/'(npm -v)
end
if test -n "$NVM_CURRENT_VERSION"
set_color green
echo -n '🅽 nvm: '
set_color -i brgreen
echo $NVM_CURRENT_VERSION
set_color normal
end
# domain
if test -n "$ACTIVE_DOMAIN_SUFFIX"
set_color yellow
echo -n '🅰 r53: '
set_color -i bryellow
echo $ACTIVE_DOMAIN_SUFFIX
set_color normal
end
# if test "$TERM_PROGRAM" = "iTerm.app"
# iterm2_prompt_mark
# end
# set Google Cloud environment
set_color brblue
echo -n '🅶 '
set_color yellow ; echo -n "conf: "
set_color -i bryellow ; echo -n $GOOGLE_CONFIG
set_color normal
set_color yellow ; echo -n ' project: '
set_color -i bryellow ; echo -n $GOOGLE_PROJECT
set_color normal
set_color yellow ; echo -n ' region: '
set_color -i bryellow ; echo -n $GOOGLE_REGION
set_color normal
set_color yellow ; echo -n ' zone: '
set_color -i bryellow ; echo $GOOGLE_ZONE
set_color normal
if test -n "$GOOGLE_APPLICATION_CREDENTIALS"
set_color -o yellow
echo -n ' GOOGLE_APPLICATION_CREDENTIALS='
set_color normal
set_color -i bryellow ; echo $GOOGLE_APPLICATION_CREDENTIALS
set_color normal
end
set_color brblue
# set Kubernetes environment
echo -n '🅺 '
set_color yellow ; echo -n 'k8s: '
set_color -i bryellow
if not string match -q "error: current-context is not set" $K8S_CLUSTER; and test (string length "$K8S_CLUSTER") -ne 0
echo -n $K8S_CLUSTER
else
echo -n "n/a"
end
set_color normal
set_color yellow ; echo -n ' short: '
set_color -i bryellow
if test -n "$K8S_CLUSTER_SHORT"
echo -n $K8S_CLUSTER_SHORT
else
echo -n "n/a"
end
set_color normal
set_color yellow ; echo -n ' version: '
set_color -i bryellow
if test -n "$K8S_CLUSTER_VERSION"
echo $K8S_CLUSTER_VERSION
else
echo "n/a"
end
set_color normal
end
# place iTerm prompt marker in case TMUX is not active
if test -z "$TMUX"
if test $TERM_PROGRAM = "iTerm.app"
iterm2_prompt_mark
# update iTerm user variables
iterm2_update_user_vars
end
end
# User
set_color $fish_color_user
echo -n (whoami)
set_color normal
echo -n ' @ '
# Host
set_color $fish_color_host
echo -n (prompt_hostname)
set_color normal
echo -n ': '
# PWD
set_color $fish_color_cwd
echo -n (prompt_pwd)
set_color normal
__terlar_git_prompt
__fish_hg_prompt
echo
if test -n "$fish_prompt_detailed_show_datetime"
echo -n (date +%Y-%m-%d\ %H:%M:%S\ )
end
if not test $last_status -eq 0
set_color $fish_color_error
end
echo -n '➤ '
set_color normal
end