-
Notifications
You must be signed in to change notification settings - Fork 0
/
executable_dot_mkps1.sh
108 lines (82 loc) · 2.54 KB
/
executable_dot_mkps1.sh
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
#!/usr/bin/env bash
# MKPS1
# (Mike Kasberg PS1)
# (Or, Make PS1)
# Different functions generate different parts (segments) of the PS1 prompt.
# Each function should leave the colors in a clean state (e.g. call reset if they changed any colors).
# For Git PS1
source /usr/lib/git-core/git-sh-prompt;
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUPSTREAM="verbose"
__mkps1_debian_chroot() {
# This string is intentionally single-quoted:
# It will be evaluated when $PS1 is evaluated to generate the prompt each time.
echo '${debian_chroot:+($debian_chroot)}';
}
__mkps1_inject_exitcode() {
local code=$1
if [ "$code" -ne "0" ]; then
echo " $code "
fi
}
__mkps1_exitcode() {
local bg_red=`tput setab 1`;
local white=`tput setaf 15`;
local reset=`tput sgr0`;
# We need to run a function at runtime to evaluate the exitcode.
echo "\[${bg_red}${white}\]\$(__mkps1_inject_exitcode \$?)\[${reset}\]"
}
__mkps1_time() {
local BG_GRAY=`tput setab 240`;
local white=`tput setaf 7`;
local reset=`tput sgr0`;
echo "\[${BG_GRAY}${white}\] \t \[${reset}\]"
}
__mkps1_username() {
local cyan=`tput setaf 45`;
local reset=`tput sgr0`;
echo "\[${cyan}\] \u \[${reset}\]";
}
__mkps1_arrows() {
local bold=`tput bold`;
local red=`tput setaf 1`;
local green=`tput setaf 34`;
local reset=`tput sgr0`;
echo "\[${bold}${red}\]🮥🮥\[${green}\]🮥\[${reset}\]";
}
__mkps1_workdir() {
local bold=`tput bold`;
local cyan=`tput setaf 45`;
local reset=`tput sgr0`;
echo "\[${bold}${cyan}\]\w\[${reset}\]";
}
__mkps1_git() {
local magenta=`tput setaf 213`;
local reset=`tput sgr0`;
# Escaping the $ is intentional:
# This is evaluated when the prompt is generated.
echo "\$(__git_ps1 ' (\[${magenta}\]%s\[${reset}\])')"
}
__mkps1_box_top() {
local cyan=`tput setaf 45`;
local reset=`tput sgr0`;
echo "\[${cyan}\]╭\[${reset}\]"
}
__mkps1_box_bottom() {
local cyan=`tput setaf 45`;
local reset=`tput sgr0`;
echo "\[${cyan}\]╰\[${reset}\]"
}
__mkps1_user_prompt() {
local bold=`tput bold`;
local reset=`tput sgr0`;
echo "\[${bold}\]\$\[${reset}\] ";
}
__mkps1() {
local ps1="\n$(__mkps1_box_top)$(__mkps1_debian_chroot)$(__mkps1_exitcode)$(__mkps1_time)$(__mkps1_username)$(__mkps1_arrows) $(__mkps1_workdir)$(__mkps1_git)\n$(__mkps1_box_bottom)$(__mkps1_user_prompt)";
echo "$ps1";
}
# To test, for example, print output before changes and after changes
# and see if the diff is correct.
# Uncomment for testing:
#__mkps1;