From 9f57a00ffecc6be1b7ebabf1a95f148d550828c9 Mon Sep 17 00:00:00 2001 From: Timo Bingmann Date: Fri, 19 Sep 2025 22:17:53 -0700 Subject: [PATCH] system/default: add prompt.nix for prompt coloring --- flake.nix | 1 + system/default/prompt.nix | 64 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 system/default/prompt.nix diff --git a/flake.nix b/flake.nix index 41e6710..d4f7b40 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,7 @@ ./system/default/editor.nix ./system/default/nix.nix ./system/default/packages.nix + ./system/default/prompt.nix ]; }; diff --git a/system/default/prompt.nix b/system/default/prompt.nix new file mode 100644 index 0000000..5b2d674 --- /dev/null +++ b/system/default/prompt.nix @@ -0,0 +1,64 @@ +{ config, pkgs, ... }: +let + # Define color codes + colors = { + deepSkyBlue = "38;5;39"; + green = "38;5;70"; + orange = "38;5;208"; + purple = "38;5;135"; + yellow = "38;5;226"; + cyan = "38;5;51"; + magenta = "38;5;201"; + lightGreen = "38;5;118"; + turquoise = "38;5;45"; + purpleBlue = "38;5;99"; + gold = "38;5;214"; + limeGreen = "38;5;155"; + lavender = "38;5;141"; + teal = "38;5;80"; + goldenYellow = "38;5;220"; + lightPurple = "38;5;147"; + }; + + # Static hostname to color mapping + hostnameColors = { + "ubi" = colors.deepSkyBlue; # Distinct blue + "teb" = colors.green; # Green + "wg1" = colors.orange; # Orange + "t1" = colors.purple; # Purple + "oc1" = colors.cyan; # Cyan + "tr1" = colors.magenta; # Magenta (distinct from tr2/tr3) + "tr2" = colors.lightGreen; # Light green (different from tr1) + "tr3" = colors.gold; # Gold (very different from tr1/tr2) + "rp1" = colors.turquoise; # Turquoise + "mab" = colors.lavender; # Lavender + "C02CLC7FLVDL" = colors.gold; # Gold + }; + + # Get the current hostname + currentHostname = config.networking.hostName; + + # Get the color for current hostname, default to teal if not in map + hostnameColor = hostnameColors.${currentHostname} or colors.teal; + + # The prompt script + promptScript = '' + # Set prompt with static color: ${hostnameColor} + if [ "$EUID" -eq 0 ]; then + # Root prompt + PS1='\[\033[1;31m\][\[\033[0m\]\[\033[1;31m\]root\[\033[0m\]\[\033[1;31m\]@\[\033[0m\]\[\033[1;${hostnameColor}m\]\h\[\033[0m\]\[\033[1;31m\]:\[\033[0m\]\[\033[1;31m\]\w\[\033[0m\]\[\033[1;31m\]]\[\033[0m\]\[\033[1;31m\]#\[\033[0m\] ' + else + # User prompt + PS1='\[\033[1;${hostnameColor}m\][\u@\h:\w]\$\[\033[0m\] ' + fi + ''; +in +{ + # Bash prompt configuration + programs.bash = { + } // (if pkgs.stdenv.isDarwin then { + interactiveShellInit = promptScript; + } else { + promptInit = promptScript; + }); +}