/
promptrc
73 lines (63 loc) · 1.76 KB
/
promptrc
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
#!/usr/bin/env bash
RED="\[\033[0;31m\]"
MAGENTA="\[\033[0;45m\]"
YELLOW="\[\033[1;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[1;34m\]"
CYAN="\[\033[1;46m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
function set_prompt_symbol () {
if test $1 -eq 0 ; then
PROMPT_SYMBOL="${LIGHT_GRAY}\$${COLOR_NONE}"
else
PROMPT_SYMBOL="${LIGHT_RED}\$${COLOR_NONE}"
fi
}
# Copied from https://github.com/jimeh/git-aware-prompt
find_git_branch() {
# Based on: http://stackoverflow.com/a/13003854/170413
local branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached*'
fi
git_branch="(${LIGHT_RED}$branch${COLOR_NONE})"
else
git_branch=""
fi
}
find_git_dirty() {
local status=$(git status --porcelain 2> /dev/null)
if [[ "$status" != "" ]]; then
git_dirty="[${BLUE}*${COLOR_NONE}]"
else
git_dirty=''
fi
}
function set_git_prompt() {
find_git_branch
find_git_dirty
GIT_PROMPT="${git_branch}${git_dirty}"
}
function set_kube_prompt()
{
KUBE_CONTEXT=$(grep 'current-context:' ~/.kube/config | cut -d ' ' -f 2)
KUBE_PROMPT="[${YELLOW}${KUBE_CONTEXT}${COLOR_NONE}]"
}
function set_bash_prompt () {
# Set the PROMPT_SYMBOL variable. We do this first so we don't lose the
# return value of the last command.
set_prompt_symbol $?
set_git_prompt
#set_kube_prompt
# Set the bash prompt variable.
PS1="${KUBE_PROMPT}${GIT_PROMPT}${COLOR_NONE}${LIGHT_GREEN}\u${COLOR_NONE}:${BLUE}\w${PROMPT_SYMBOL} "
}
# Tell bash to execute this function just before displaying its prompt.
PROMPT_COMMAND=set_bash_prompt
. $HOME/.dotfiles/z.sh
. $HOME/.dotfiles/git-completion.bash