commit 335836dac78df5f140a4d294467e7d6c2c11fa0b Author: Nettika Date: Tue Feb 10 01:54:06 2026 -0800 Initial commit diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..481b30c --- /dev/null +++ b/flake.nix @@ -0,0 +1,9 @@ +{ + description = "Serval Prompt"; + + outputs = + { ... }: + { + nixosModules.default = import ./module.nix; + }; +} diff --git a/module.nix b/module.nix new file mode 100644 index 0000000..9b39feb --- /dev/null +++ b/module.nix @@ -0,0 +1,62 @@ +{ + lib, + pkgs, + config, + ... +}: + +let + inherit (lib) + mkOption + mkEnableOption + mkIf + optionalString + types + getExe + ; + inherit (pkgs) gitMinimal; + cfg = config.programs.fish.servalPrompt; + +in +{ + options.programs.fish.servalPrompt = { + enable = mkEnableOption "Serval Prompt"; + prefix = mkOption { + type = types.str; + description = "Prompt prefix."; + example = "🐆"; + }; + }; + + config = mkIf cfg.enable { + programs.fish = { + promptInit = '' + set -g fish_prompt_pwd_full_dirs 999 + + function fish_prompt + set -l uc (fish_is_root_user && echo red || echo magenta) + set -l cc (fish_is_root_user && echo red || echo brgreen) + printf '%s %s%s %s%s%s > ' \ + '${cfg.prefix}' \ + (set_color $uc) $USER \ + (set_color $cc) (prompt_pwd) \ + (set_color normal) + end + + function fish_right_prompt + set -l branch (${getExe gitMinimal} branch --show-current 2>/dev/null) + and printf '%s%s' (set_color bryellow) $branch + end + '' + + optionalString config.services.openssh.enable '' + + function fish_greeting + test -n "$SSH_CLIENT" -a $SHLVL -eq 1 + and printf 'Connected to ${cfg.prefix} %s%s%s as %s%s%s\n' \ + (set_color cyan) $hostname (set_color normal) \ + (set_color magenta) $USER (set_color normal) + end + ''; + }; + }; +}