63 lines
1.5 KiB
Nix
63 lines
1.5 KiB
Nix
|
|
{
|
||
|
|
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
|
||
|
|
'';
|
||
|
|
};
|
||
|
|
};
|
||
|
|
}
|