-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc_ps1_colors
57 lines (50 loc) · 1.62 KB
/
bashrc_ps1_colors
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
# -*- shell-script -*-
#### Colors ########################################
COLOR_RED="\e[0;31m"
COLOR_YELLOW="\e[1;33m"
COLOR_GREEN="\e[0;32m"
COLOR_BLUE="\e[0;34m"
COLOR_LIGHT_BLUE="\e[1;34m"
COLOR_PURPLE="\e[0;35m"
COLOR_LIGHT_RED="\e[1;31m"
COLOR_LIGHT_GREEN="\e[1;32m"
COLOR_WHITE="\e[1;37m"
COLOR_LIGHT_GRAY="\e[0;37m"
COLOR_NONE="\e[0m"
COLOR_INVERT="\e[7m"
### PS1 ############################################
USER_COLOR=${COLOR_LIGHT_GRAY}
HOST_COLOR=${COLOR_LIGHT_BLUE}${COLOR_INVERT}
PATH_COLOR=${COLOR_WHITE}
VENV_COLOR=${COLOR_BLUE}
CONDA_COLOR=${COLOR_RED}
print_venv() {
if [ -z "$VIRTUAL_ENV" ]; then
PYTHON_VIRTUALENV=""
else
PYTHON_VIRTUALENV="[${VENV_COLOR}$( basename \"${VIRTUAL_ENV} \" )${COLOR_NONE}]"
fi
echo $PYTHON_VIRTUALENV
}
print_conda() {
if [ -z "$CONDA_PREFIX" ]; then
CONDA_ENV=""
else
CONDA_ENV="[${CONDA_COLOR}$( basename \"${CONDA_PREFIX} \" )${COLOR_NONE}]"
fi
echo $CONDA_ENV
}
parse_git_branch() {
branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/^* \(.*\)/\1/')
status=$([[ $(git status --untracked-files=no --porcelain 2> /dev/null) ]] && echo " *")
untracked=$([[ ! -z $(git ls-files --others --exclude-standard 2> /dev/null) ]] && echo " +")
[[ $branch ]] && echo "[$branch$status$untracked]"
}
ps1_prompt() {
ps1_status=$?
ps1_git=$(parse_git_branch)
ps1_venv=$(print_venv)
ps1_conda=$(print_conda)
PS1="${ps1_conda}${ps1_venv}[${USER_COLOR}\u${COLOR_NONE}@${HOST_COLOR}\h${COLOR_NONE}:${PATH_COLOR}\w${COLOR_NONE}]${ps1_git}\n${ps1_status}>>$ "
}
PROMPT_COMMAND="ps1_prompt;$PROMPT_COMMAND"