From eea3b702de3cfcbb6f9a68fa8acc56df16631601 Mon Sep 17 00:00:00 2001 From: steffen Date: Sat, 24 Jan 2026 02:48:40 +0000 Subject: [PATCH] Update ps1.sh --- ps1.sh | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ps1.sh b/ps1.sh index 5704ad4..536d381 100644 --- a/ps1.sh +++ b/ps1.sh @@ -31,12 +31,9 @@ esac # 23:00-04:59 natt # ------------------------------------------------- _ps1_emoji() { - local hh mm + local hh mm h m hh="$(TZ=Europe/Oslo date +%H)" mm="$(TZ=Europe/Oslo date +%M)" - - # Strip leading zeros safely - local h m h=$((10#$hh)) m=$((10#$mm)) @@ -45,7 +42,7 @@ _ps1_emoji() { elif (( h >= 9 && h <= 10 )); then printf '%s' "☕" # formiddag elif (( h == 11 && m < 30 )); then - printf '%s' "🥪" # lunsj (11:00-11:29) + printf '%s' "🥪" # lunsj elif (( (h == 11 && m >= 30) || (h >= 12 && h <= 15) )); then printf '%s' "💻" # dag elif (( h == 16 )); then @@ -53,13 +50,14 @@ _ps1_emoji() { elif (( h >= 17 && h <= 22 )); then printf '%s' "🌆" # kveld else - printf '%s' "🌙" # natt (23-04) + printf '%s' "🌙" # natt fi } # ------------------------------------------------- # Build PS1 (boxy + pastel contrast + full path) -# Uses $(pwd) so you see /home/user instead of ~ +# NOTE: We DO NOT use printf %b, because \u etc are PS1 escapes (not printf escapes) +# We keep PS1 escapes as \\u, \\h, \\d, \\A, \\n so bash expands them in the prompt. # ------------------------------------------------- _ps1_build() { local emoji path @@ -75,11 +73,12 @@ _ps1_build() { local ACC="\[\e[38;5;229m\]" local RST="\[\e[0m\]" - # Layout: - # ╭─(date time)-(user@host)-(fullpath) - # ╰──➜ $ + emoji - printf '%b' \ -"${BOX}╭─(${ACC}\d${BOX} ${ACC}\A${BOX})-(${VAL}\u${BOX}@${VAL}\h${BOX})-(${VAL}${path}${BOX})${RST}\n${BOX}╰──➜ ${RST}\\$${emoji} " + # Use PS1 escapes for date/time/user/host and a PS1 newline (\\n) + # Use full path from $(pwd) so /home/user is shown (no ~ shortening) + local ps1 + ps1="${BOX}╭─(${ACC}\\d${BOX} ${ACC}\\A${BOX})-(${VAL}\\u${BOX}@${VAL}\\h${BOX})-(${VAL}${path}${BOX})${RST}\\n${BOX}╰──➜ ${RST}\\$${emoji} " + + printf '%s' "$ps1" } # ------------------------------------------------- @@ -96,5 +95,5 @@ ps1_off() { PROMPT_COMMAND="$__PS1_PREV_PROMPT_COMMAND" } -# Optional: turn it on immediately when sourced (comment out if you don't want auto-enable) +# Optional auto-enable (leave commented) # ps1_on