From 0b7e362582c8ca989960b2f0878d46c6489569f9 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 20 Aug 2023 18:33:26 +0200 Subject: [PATCH] bash/ps1 --- bash/bash/prompt.sh | 46 ++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/bash/bash/prompt.sh b/bash/bash/prompt.sh index b68611d..a245867 100644 --- a/bash/bash/prompt.sh +++ b/bash/bash/prompt.sh @@ -1,15 +1,35 @@ -PS1="\ -└ \t\ - – \e[0;31m\${?}\e[0m\ - – \e[0;32m\u\e[0m\ - @ \e[0;33m\h\e[0m\ -" -if [ "$(type -t __git_ps1)" == 'function' ] ; then - PS1="${PS1} –\e[0;35m\$(__git_ps1)\e[0m" -fi -PS1="${PS1} -┌ \e[0;36m\${PWD}\e[0m -│ " - PS2="\ │ " + +function ps1 { +local code=${1} +local date="$(date +%H:%M:%S)" +local git +local host="$(hostname)" +local path="${PWD}" +local real="$(realpath "${path}")" +local user="${USER}" +local view="\ +└ ${date}\ + – \e[0;31m${code}\e[0m\ + – \e[0;32m${user}\e[0m\ + @ \e[0;33m${host}\e[0m\ +" + if [ "$(type -t __git_ps1)" == 'function' ] ; then + git="$(__git_ps1)" + if [ "${git}" ] ; then + view="${view} –\e[0;35m${git}\e[0m" + fi + fi + view="${view} +┌ " + if [ "${path}" != "${real}" ] ; then + view="${view}\e[0;36m${real}\e[0m +├ " + fi + view="${view}\e[0;36m${path}\e[0m +${PS2}" + echo -e "${view}" +} + +PS1='$(eval ps1 ${?})'