From ba3b90366b7ca3ad7aab79757430657b9170ecc7 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 16 Nov 2024 02:19:41 +0100 Subject: [PATCH] wip/colors --- shell/shell.sh | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/shell/shell.sh b/shell/shell.sh index e164562..7fde50e 100644 --- a/shell/shell.sh +++ b/shell/shell.sh @@ -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" - fi + case "${SH}" in + "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}" }