home · contact · privacy
Also enhance root prompt, but differentiate prompt colors. master
authorPlom Heller <plom@plomlompom.com>
Fri, 25 Sep 2026 00:28:28 +0000 (02:28 +0200)
committerPlom Heller <plom@plomlompom.com>
Fri, 25 Sep 2026 00:28:28 +0000 (02:28 +0200)
CLAUDE.md
home/any/.profile.d/prompt.sh [new file with mode: 0644]
home/root/.config/prompt_color_number [new file with mode: 0644]
home/user/.config/prompt_color_number [new file with mode: 0644]
home/user/.profile.d/prompt.sh [deleted file]

index 5c6d9a6a40d7d58e4ff89d3947c15a362a38a772..d7235c9e522f9b0e6459114dec694855f1063f26 100644 (file)
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -689,6 +689,18 @@ in `.profile.d/` as `*.sh`, sourced by the loop line in `~/.profile`.
   `LS_COLORS` is empty: a shell reached via `su -l` (root's, from the user)
   loses foot's `COLORTERM`, and `dircolors` has no database entry for foot's
   `TERM=foot`, which would otherwise leave `ls` uncolored.
+- `.profile.d/prompt.sh` — colored (bold) `[<date>/<time>/<zone>
+  user@host:path]$` `PS1`, with `PS2`/`PS3`/`PS4` matching. The `tput setaf`
+  color number is read from `~/.config/prompt_color_number` (see below),
+  falling back to `COLOR_DEFAULT` (7, white) if that's unreadable, so an
+  account without the file still gets a working prompt. Colors from `tput`;
+  `\D{...}`/`\u`/`\h`/`\w` instead of forked `date`/`pwd`. In bash the
+  colors are wrapped in `\[ \]` for readline's width counting, except `PS3`
+  (printed verbatim by `select`; bare codes). Helpers are `local`s of a
+  throwaway `_dot_profile_dot_prompt` function, unset after the call. Takes
+  effect because the loop line sits at the very end of `~/.profile`, after
+  Debian's stock one has sourced `~/.bashrc` (which sets its own `PS1`), so
+  this fragment gets the last word.
 
 ### `home/root/` and `home/user/`
 
@@ -699,21 +711,16 @@ in `.profile.d/` as `*.sh`, sourced by the loop line in `~/.profile`.
   Why: the `60-poweroff-on-failure.conf` drop-in only guards a hibernate
   failure reached through systemd's own unit, not a direct
   `systemctl hibernate`; `hibernate_safe` closes that gap.
+- `.config/prompt_color_number` (both, differing) — the prompt color read
+  by `prompt.sh`: 1 (red) for root, 2 (green) for the user. A plain data
+  file, so an account owner can swap the symlink for a file of their own,
+  which `link_home` then leaves alone.
 
 ### `home/user/` only
 
 - `.profile.d/ssh-agent.sh` — starts `ssh-agent` and `ssh-add -q` once per
   login, guarded by `[ -z "${SSH_AGENT_PID}" ]` (so e.g. a second `foot`
   window doesn't start another). Root needs no agent.
-- `.profile.d/prompt.sh` — colored (bold, `COLOR_NUMBER`, default green)
-  `[<date>/<time>/<zone> user@host:path]$` `PS1`, with `PS2`/`PS3`/`PS4`
-  matching. Colors from `tput`; `\D{...}`/`\u`/`\h`/`\w` instead of forked
-  `date`/`pwd`. In bash the colors are wrapped in `\[ \]` for readline's
-  width counting, except `PS3` (printed verbatim by `select`; bare codes).
-  Helpers are `local`s of a throwaway `_dot_profile_dot_prompt` function,
-  unset after the call. Takes effect because the loop line sits at the very
-  end of `~/.profile`, after Debian's stock one has sourced `~/.bashrc`
-  (which sets its own `PS1`), so this fragment gets the last word.
 - `.profile.d/kb.sh` — `kb` alias: `swaymsg 'input * xkb_switch_layout next'`.
 - `.gitconfig` — minimal `[user]` section.
 - `.config/foot/foot.ini` — `font=monospace:size=14.5` and
diff --git a/home/any/.profile.d/prompt.sh b/home/any/.profile.d/prompt.sh
new file mode 100644 (file)
index 0000000..3387c2b
--- /dev/null
@@ -0,0 +1,26 @@
+_dot_profile_dot_prompt() {
+    local COLOR_NUMBER
+    local COLOR_ON
+    local COLOR_OFF
+    local COLOR_DEFAULT=7
+    local PATH_COLOR_NUMBER="${HOME}/.config/prompt_color_number"
+    # tput setaf numbers, e.g. 1 red, 2 green, 7 white
+    COLOR_NUMBER=$(cat "${PATH_COLOR_NUMBER}" 2>/dev/null) \
+        || COLOR_NUMBER="${COLOR_DEFAULT}"
+    COLOR_ON="$(tput setaf "${COLOR_NUMBER}" 2>/dev/null)"
+    COLOR_ON="${COLOR_ON}$(tput bold 2>/dev/null)"
+    COLOR_OFF="$(tput sgr0 2>/dev/null)"
+    # Bash confuses the line length when not told not to count escape
+    # sequences. PS3 is printed verbatim by "select", so it must get the
+    # unwrapped codes.
+    PS3="${COLOR_ON}select: ${COLOR_OFF}"
+    if [ -n "${BASH:-}" ]; then
+        COLOR_ON="\[${COLOR_ON}\]"
+        COLOR_OFF="\[${COLOR_OFF}\]"
+    fi
+    PS1="${COLOR_ON}[\D{%Y-%m-%d/%H:%M:%S/%Z} \u@\h:\w]\$ ${COLOR_OFF}"
+    PS2="${COLOR_ON}> ${COLOR_OFF}"
+    PS4="${COLOR_ON}+ ${COLOR_OFF}"
+}
+_dot_profile_dot_prompt
+unset -f _dot_profile_dot_prompt
diff --git a/home/root/.config/prompt_color_number b/home/root/.config/prompt_color_number
new file mode 100644 (file)
index 0000000..d00491f
--- /dev/null
@@ -0,0 +1 @@
+1
diff --git a/home/user/.config/prompt_color_number b/home/user/.config/prompt_color_number
new file mode 100644 (file)
index 0000000..d8263ee
--- /dev/null
@@ -0,0 +1 @@
+2
\ No newline at end of file
diff --git a/home/user/.profile.d/prompt.sh b/home/user/.profile.d/prompt.sh
deleted file mode 100644 (file)
index c543779..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-_dot_profile_dot_prompt() {
-    local COLOR_NUMBER=2
-    local COLOR_ON
-    local COLOR_OFF
-    COLOR_ON="$(tput setaf "${COLOR_NUMBER}" 2>/dev/null)$(tput bold 2>/dev/null)"
-    COLOR_OFF="$(tput sgr0 2>/dev/null)"
-    # Bash confuses the line length when not told not to count escape
-    # sequences. PS3 is printed verbatim by "select", so it must get the
-    # unwrapped codes.
-    PS3="${COLOR_ON}select: ${COLOR_OFF}"
-    if [ -n "${BASH:-}" ]; then
-        COLOR_ON="\[${COLOR_ON}\]"
-        COLOR_OFF="\[${COLOR_OFF}\]"
-    fi
-    PS1="${COLOR_ON}[\D{%Y-%m-%d/%H:%M:%S/%Z} \u@\h:\w]\$ ${COLOR_OFF}"
-    PS2="${COLOR_ON}> ${COLOR_OFF}"
-    PS4="${COLOR_ON}+ ${COLOR_OFF}"
-}
-_dot_profile_dot_prompt
-unset -f _dot_profile_dot_prompt