-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkprompt
159 lines (145 loc) · 4.83 KB
/
mkprompt
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#
# rebuilds cache file '~/var/bash/ps1' for sourcing
# (after '~/.bash/prompt' has changed, tested during shell init)
# (see also func.d/prompt for a way to configure in-session)
#
##############################################################################
# TODO: put these in a configuration file somewhere
# TODO: perhaps combine this and ~/.bash/func.d/prompt ?
#
shell_init_prompt_color=${PROMPT_COLORS:-'1'}
shell_init_prompt_dollar=${PROMPT_DOLLAR:-'1'}
shell_init_prompt_details=${PROMPT_DETAILS:-'0'}
shell_init_prompt_rebuild=${PROMPT_REBUILD:-'0'}
export HOSTNAME=`hostname`
###
shell_init_prompt ()
{
local color=$((shell_init_prompt_color))
local dollar=$((shell_init_prompt_dollar))
local details=$((shell_init_prompt_details))
local rebuild=$((shell_init_prompt_rebuild))
local colors=~/.bash/colors
local infile=~/.bash/init.d/mkprompt
local outfile=~/var/bash/ps1
if test $infile -nt $outfile || ((rebuild))
then
echo "$FUNCNAME: source changed, rebuilding PS1"
((color)) && source ~/.bash/colors
# TODO: put the below in a separate file that's sourced.
# tried a few variations and could not get the evaluation
# right to output a sourcable file. maybe maintain this
# in an external language?
#
######################################################################
cat >| $outfile <<- .
#
# \"~/.bash/init.d/mkprompt\": source for editing, composes PS1
# \"~/var/bash/ps1\": cached PS1, rebuilt when \"mkprompt\" changes
#
# SAVE RETURN CODE if doing a subshell, and exit with
# it (see 'rval' in examples below), so exit status is
# correct for the outermost [interactive] shell
#
esetenv PS1 \\
"\[$CLR_solid_flat_fgwhite_bgblack\]" "\n" \\
.
if ((details))
then cat >> $outfile <<- .
\\
"\[$CLR_solid_flat_fgcyan_bgblack\]" " \t " \\
"\[$CLR_solid_bold_fggreen_bgblack\]" \\
"\\\${SSH_TTY:+" \\
"\\\${LHOST:-" \\
"\\\${HOSTNAME%%.*}}}" \\
"\[$CLR_solid_flat_fgcyan_bgblack\]" "\\\${SSH_TTY:+:}" \\
"\[$CLR_solid_bold_fgcyan_bgblack\]" "\\\${GOASSOC} " \\
"\[$CLR_solid_bold_fgblue_bgblack\]" "l" \\
"\[$CLR_solid_flat_fgcyan_bgblack\]" "\\\${GOTTY_NUM} " \\
"\[$CLR_solid_bold_fgblue_bgblack\]" "h" \\
"\[$CLR_solid_flat_fgcyan_bgblack\]" "\! " \\
"\[$CLR_solid_bold_fgblue_bgblack\]" "c" \\
"\[$CLR_solid_flat_fgcyan_bgblack\]" "\# " \\
"\[$CLR_solid_bold_fgblue_bgblack\]" "q\\\$(
rval=\\\$?
depth=\\\${#DIRSTACK[@]}
if ((depth == 1))
then printf %s%u \"\[$CLR_solid_flat_fgcyan_bgblack\]\" \\\$depth
else printf %s%u \"\[$CLR_solid_bold_fgmagenta_bgblack\]\" \\\$depth
fi
exit \\\$rval
)" \\
" " \\
"\[$CLR_solid_bold_fgblue_bgblack\]" "s\\\$(
rval=\\\$?
shlvl=\\\$SHLVL
if ((shlvl == 1)) || (((shlvl == 2)) && [[ \"\\\$DISPLAY\" ]])
then printf %s%u \"\[$CLR_solid_flat_fgcyan_bgblack\]\" \\\$shlvl
else printf %s%u \"\[$CLR_solid_bold_fgmagenta_bgblack\]\" \\\$shlvl
fi
exit \\\$rval
)" \\
" " \\
"\[$CLR_solid_bold_fgblue_bgblack\]" "j\\\$(
rval=\\\$?
running=\"\\\$(wc -l <(compgen -A running))\"
stopped=\"\\\$(wc -l <(compgen -A stopped))\"
running=\\\${running%% *}
stopped=\\\${stopped%% *}
njobs=\\\$((running + stopped))
if ((njobs))
then printf %s%u \"\[$CLR_solid_bold_fgmagenta_bgblack\]\" \\\$njobs
else printf %s%u \"\[$CLR_solid_flat_fgcyan_bgblack\]\" \\\$njobs
fi
exit \\\$rval
)" \\
" " \\
"\[$CLR_solid_bold_fgblue_bgblack\]" "r\\\$(
rval=\\\${?}
if ((rval))
then printf %s%u \"\[$CLR_solid_bold_fgmagenta_bgblack\]\" \\\$rval
else printf %s%u \"\[$CLR_solid_flat_fgcyan_bgblack\]\" \\\$rval
fi
exit \\\$rval
)" \\
" " \\
"\[$CLR_solid_bold_fgwhite_bgblack\]" "[" \\
"\[$CLR_solid_bold_fgcyan_bgblack\]" "\W" \\
"\[$CLR_solid_bold_fgwhite_bgblack\]" "]" \\
"\n" \\
.
fi
if ((dollar))
then cat >> $outfile <<- .
" " \\
"\\\$(
rval=\\\${?}
((rval == 148)) && rval=0 # 128 + 20 (SIGTSTP)
[[ \\\$(compgen -A running) || \\\$(compgen -A stopped) ]]
jobsbool=\\\$?
if ((rval == 0 && jobsbool == 0)); then printf \"\[$CLR_solid_bold_fgyellow_bgblack\]\"
elif ((rval == 0 && jobsbool == 1)); then printf \"\[$CLR_solid_bold_fggreen_bgblack\]\"
elif ((rval > 0 && jobsbool == 0)); then printf \"\[$CLR_solid_bold_fgmagenta_bgblack\]\"
elif ((rval > 0 && jobsbool == 1)); then printf \"\[$CLR_solid_bold_fgred_bgblack\]\"
fi
printf %c \\\\$
exit \\\$rval
)" \\
" " \\
"\[$CLR_solid_flat_fgwhite_bgblack\]"
esetenv PS2 \\
"\[$CLR_solid_bold_fgyellow_bgblack\]" "" \\
"\[$CLR_solid_flat_fgwhite_bgblack\]" " " \\
""
.
fi
##############################################################################
else
# use the cached prompt
:
fi
source $outfile
}
# process shell_init_*()
#
source ~/.bash/initfuncs