wip/colors

This commit is contained in:
Marc Beninca 2024-11-16 02:19:41 +01:00
parent 347951cbdf
commit ba3b90366b
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -2,14 +2,30 @@ SH="$(cat /proc/$$/comm)"
shell_color() {
local code="${1}"
if [ -n "${code}" ]; then
case "${SH}" in
"bash") printf "\e[0;" ;;
*) printf "\033[" ;;
esac
printf "%s" "${code}m"
"bash")
printf "\e[0"
if [ -n "${code}" ]; then
printf "%s" ";${code}"
fi
;;
*)
printf "\033["
if [ -n "${code}" ]; then
printf "%s" "${code}"
else
printf "0"
fi
;;
esac
printf "m"
}
SH_DEFAULT="$(shell_color)"
SH_GREEN="$(shell_color 31)"
SH_RED="$(shell_color 32)"
SH_BROWN="$(shell_color 33)"
SH_MAGENTA="$(shell_color 35)"
SH_CYAN="$(shell_color 36)"
case "${SH}" in
"bash")
@ -40,25 +56,25 @@ ps1() {
local user="${USER}"
local view="└ "
if [ "${code}" -ne 0 ]; then
view="${view}\e[0;31m"
view="${view}${SH_GREEN}"
else
view="${view}\e[0;32m"
view="${view}${SH_RED}"
fi
view="${view}${code}\e[0m @ \e[0;33m${date}\e[0m"
view="${view}${code}${SH_DEFAULT} @ ${SH_BROWN}${date}${SH_DEFAULT}"
if [ "$(type -t __git_ps1)" = "function" ]; then
git="$(__git_ps1)"
if [ -n "${git}" ]; then
view="${view}\e[0;35m${git}\e[0m"
view="${view}${SH_MAGENTA}${git}${SH_DEFAULT}"
fi
fi
view="${view}\n\e[0;36m${path}\e[0m"
view="${view}\n${SH_CYAN}${path}${SH_DEFAULT}"
view="${view}\n┌ "
if [ "${id}" -eq 0 ]; then
view="${view}\e[0;31m"
view="${view}${SH_GREEN}"
else
view="${view}\e[0;32m"
view="${view}${SH_RED}"
fi
view="${view}${user}\e[0m @ \e[0;33m${host}\e[0m"
view="${view}${user}${SH_DEFAULT} @ ${SH_BROWN}${host}${SH_DEFAULT}"
echo -e "${view}\n${PS2}"
}