-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_prompt
74 lines (68 loc) · 2.89 KB
/
.bash_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# simple bash prompt by koljah
# https://github.com/koljah-de/simple-bash-prompt/
# define the color of the simple-bash-prompt
simple_bash_prompt_bracket_color="\033[1;32m"
simple_bash_prompt_command_color="\033[0;97m"
simple_bash_prompt_device_color="\033[1;34m"
simple_bash_prompt_dir_color="\033[1;37m"
simple_bash_prompt_git_branch_color="\033[1;33m"
simple_bash_prompt_git_color="\033[0;33m"
simple_bash_prompt_user_color="\033[1;36m"
simple_bash_prompt_separator_color="\033[1;37m"
simple_bash_prompt_symbol_color="\033[1;31m"
simple_bash_prompt_reset="\033[m"
# define the prompt terminator character
simple_bash_prompt_symbol="\\$"
# set the color with the exit status of the last command
simple_bash_prompt_exit_status_color () {
if [ $1 -eq 0 ]; then
echo -e "\033[0;32m"
else
echo -e "\033[0;31m"
fi
}
# check if current directory is a git repo
simple_bash_prompt_is_git_repo () {
git rev-parse 2> /dev/null
}
# print the git branch
simple_bash_prompt_get_git_branch () {
simple_bash_prompt_git_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [ "$simple_bash_prompt_git_branch" = "HEAD" ]; then
echo "no branch"
else
echo $simple_bash_prompt_git_branch
fi
}
# define the simple-bash-prompt
simple_bash_prompt_build_prompt () {
simple_bash_prompt_exit_status=$?
simple_bash_prompt="\[\$(simple_bash_prompt_exit_status_color $simple_bash_prompt_exit_status)\]┬─\
\[$simple_bash_prompt_bracket_color\][\
\[$simple_bash_prompt_user_color\]\u\
\[$simple_bash_prompt_separator_color\]@\
\[$simple_bash_prompt_device_color\]\h\
\[$simple_bash_prompt_separator_color\]:\
\[$simple_bash_prompt_dir_color\]\w\
\[$simple_bash_prompt_bracket_color\]]\
\[\$(simple_bash_prompt_exit_status_color $simple_bash_prompt_exit_status)\]─\
\[$simple_bash_prompt_bracket_color\][\
\[\$(simple_bash_prompt_exit_status_color $simple_bash_prompt_exit_status)\]\t\
\[$simple_bash_prompt_bracket_color\]]"
if $(simple_bash_prompt_is_git_repo); then
simple_bash_prompt+="\[\$(simple_bash_prompt_exit_status_color $simple_bash_prompt_exit_status)\]─"
simple_bash_prompt+="\[$simple_bash_prompt_git_color\]["
simple_bash_prompt+="\[$simple_bash_prompt_git_branch_color\]\$(simple_bash_prompt_get_git_branch)"
simple_bash_prompt+="\[$simple_bash_prompt_git_color\]]"
fi
if [ "$TERM" = "linux" ]; then
simple_bash_prompt+="\n\[\$(simple_bash_prompt_exit_status_color $simple_bash_prompt_exit_status)\]└─>"
simple_bash_prompt+="\[$simple_bash_prompt_symbol_color\]$simple_bash_prompt_symbol \[$simple_bash_prompt_reset\]"
else
simple_bash_prompt+="\n\[\$(simple_bash_prompt_exit_status_color $simple_bash_prompt_exit_status)\]╰─>"
simple_bash_prompt+="\[$simple_bash_prompt_symbol_color\]$simple_bash_prompt_symbol \[$simple_bash_prompt_reset\]"
fi
PS1=$simple_bash_prompt
}
export PROMPT_COMMAND=simple_bash_prompt_build_prompt