-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc_prompt
71 lines (59 loc) · 2.14 KB
/
.bashrc_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
#----- header -----
[ "${0##*/}" != "${BASH_SOURCE##*/}" ] || { >&2 echo -e "ERROR\tfile must be sourced ($0)"; return 2; }
# prevent multiple-inclusion
__link=`readlink -f "$BASH_SOURCE"`
declare -n __tag=SOURCE_${__link//[^a-zA-Z0-9_]/}
[ ${__tag:-0} -eq 0 ] || return 0
__tag=1
#------------------
# ANSI color codes - https://www.shellhacks.com/bash-colors
# PS1 requires wrapping in escaped brackets
#declare -A PS_COLORS=( ...
RS='\[\e[0m\]' # reset
HC='\[\e[1m\]' # bold/hicolor
UL='\[\e[4m\]' # underline
INV='\[\e[7m\]' # inverse background and foreground
# [1;31m yields pink
FBLK='\[\e[30m\]' # foreground black
FRED='\[\e[31m\]' # foreground red
FGRN='\[\e[32m\]' # foreground green
FYEL='\[\e[33m\]' # foreground yellow
FBLE='\[\e[34m\]' # foreground blue
FMAG='\[\e[35m\]' # foreground magenta
FCYN='\[\e[36m\]' # foreground cyan
FWHT='\[\e[37m\]' # foreground white
BBLK='\[\e[40m\]' # background black
BRED='\[\e[41m\]' # background red
BGRN='\[\e[42m\]' # background green
BYEL='\[\e[43m\]' # background yellow
BBLE='\[\e[44m\]' # background blue
BMAG='\[\e[45m\]' # background magenta
BCYN='\[\e[46m\]' # background cyan
BWHT='\[\e[47m\]' # background white
# defaults
PS_SCREEN='\[\033k\033\134\]' # missing '\h', '%n', or '$1' after 33k?
#alt: echo -ne "\ek<XXX>\e\\"
PS_PREFIX="\n${FCYN}\u${RS}@${FGRN}\h${RS} ${FYEL}\w${RS}"
PS1="${PS_PREFIX}\n\! \$ "
# Examples:
# for ROOT
# PS1="\n${FRED}\u${RS}@${FGRN}\h ${FYEL}\w\n${BRED}\!;\j${RS} \$ "
#
#PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\!,\j \$ "
#\[\033[36m\][\t]\[\033[32m\][\u@\h:\[\033[33m\]\w\[\033[32m\]]-> \[\033[0m\]
function __prompt() {
local RC=$? fn
PS1=${PS_PREFIX}
while read fn; do
[ -n "$fn" ] || continue
PS1+="$( $fn )"
done < <( IFS=$'\n'; echo "${__prompts[*]}" ) #FIXME rename to __bash_prompts
#alt: declare -F | awk '{ print $NF; }' | grep -E '^__prompt\.' # slow
[ $EUID -eq 0 ] && PS1+="${BRED}"
[ $RC -eq 0 ] && unset RC
PS1+="\n${INV}\A${RS} \!${RC:+($RC)}$RS \$ "
}
PROMPT_COMMAND=__prompt
# Whenever displaying the prompt, write the previous line to disk
#PROMPT_COMMAND="history -a"
# vim: expandtab:ts=8:sw=4