1
0

Compare commits

..

2 Commits

Author SHA1 Message Date
9f57a00ffe system/default: add prompt.nix for prompt coloring 2025-09-19 22:17:53 -07:00
6cc3a633e6 enable formatter 2025-09-19 22:17:25 -07:00
2 changed files with 105 additions and 38 deletions

View File

@@ -5,14 +5,17 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
}; };
outputs = { self, nixpkgs, ... }: outputs = { self, nixpkgs, ... }: {
{ # Set up formatter.
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
# System Modules # System Modules
nixosModules.default = { ... }: { nixosModules.default = { ... }: {
imports = [ imports = [
./system/default/editor.nix ./system/default/editor.nix
./system/default/nix.nix ./system/default/nix.nix
./system/default/packages.nix ./system/default/packages.nix
./system/default/prompt.nix
]; ];
}; };

64
system/default/prompt.nix Normal file
View File

@@ -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;
});
}