summaryrefslogtreecommitdiff
path: root/.config/bash/rc.d/99_ps1.sh
blob: 450e118ee6d1705440a3a4274ba779b8c66739b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/hint/bash

if tput setaf 1 &>/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	RESET="\\[$(tput sgr0)\\]"
	BOLD="\\[$(tput bold)\\]"
	RED="\\[$(tput setaf 1)\\]"
	GREEN="\\[$(tput setaf 2)\\]"
	BLUE="\\[$(tput setaf 4)\\]"

	STATUS="${BOLD}["
	STATUS+="\$(v=\$?; [[ \$v = 0 ]] && c='${GREEN}' || c='${RED}'; printf %s%03i \$c \$v)"
	STATUS+="${RESET}${BOLD}]${RESET}"
else
	STATUS='[$(printf "%03i" $?)]'
fi
PS1="${STATUS} ${BOLD}${GREEN}\u@\h${BLUE}:\w${RESET}${PS1_EXTRA}\\n\\$ "
unset RESET BOLD RED GREEN BLUE STATUS PS1_EXTRA