-
Notifications
You must be signed in to change notification settings - Fork 1
/
prompt
58 lines (51 loc) · 1.96 KB
/
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
enhanced_pwd() {
# Same as %~ but doesn't replace env vars
echo "${PWD/$HOME/~}"
}
git_info() {
# Attempt to get the current branch/SHA1; return if not in a git repo
ref=$(current-branch) || return
st=$(git status --porcelain 2> /dev/null)
# Show the current branch, colored depending on the repo's status
if [[ $(echo $st | grep -c '^ M') > 0 ]]; then
# Uncomitted changes
echo " on %{$fg[yellow]%}$ref%{$reset_color%}"
elif [[ $(echo $st | grep -c '^??') > 0 ]]; then
# Untracked files
echo " on %{$fg[red]%}$ref%{$reset_color%}"
else
echo " on %{$fg[green]%}$ref%{$reset_color%}"
fi
}
k8s_info() {
ctx=$(kubectl config current-context)
echo " on %{$fg[blue]%}k8s $ctx%{$reset_color%}"
}
ruby_info() {
# Show the current rbenv ruby, if set for shell/locally
if [[ -n $RBENV_VERSION || -n $(rbenv local 2> /dev/null) ]]; then
echo " with %{$fg[red]%}ruby $(rbenv version-name)%{$reset_color%}"
fi
}
python_info() {
# Show the current pyenv python/virtualenv, if set for shell/locally
if [[ -n $PYENV_VERSION || -n $(pyenv local 2> /dev/null) ]]; then
echo " with %{$fg[blue]%}python $(pyenv version-name)%{$reset_color%}"
fi
}
elixir_info() {
# Show the current exenv elixir, if set for shell/locally
if [[ -n $EXENV_VERSION || -n $(exenv local 2> /dev/null) ]]; then
echo " with %{$fg[magenta]%}elixir $(exenv version-name)%{$reset_color%}"
fi
}
node_info() {
# Show the current nodenv node, if set for shell/locally
if [[ -n $NODENV_VERSION || -n $(nodenv local 2> /dev/null) ]]; then
echo " with %{$fg[yellow]%}node $(nodenv version-name)%{$reset_color%}"
fi
}
# Have a nicer prompt: USER at HOST in PWD[ on GIT][ on K8S][ with RUBY][ with PYTHON][ with ELIXIR][ with NODE]
PROMPT='
%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[cyan]%}%m%{$reset_color%} in %{$fg[yellow]%}$(enhanced_pwd)%{$reset_color%}$(git_info)$(k8s_info)$(ruby_info)$(python_info)$(elixir_info)$(node_info)
%(?:$ :%{$fg[red]%}!%{$reset_color%} )'