Files
nixos/modules/terminal/fish.nix
2026-09-30 16:51:03 +02:00

86 lines
2.2 KiB
Nix

{ config, lib, ... }:
let
# automatically discover functions in the relative fish functions directory
fishFuncDir = ./fish-functions;
fishFuncs = lib.attrsets.mapAttrs'
(name: _: lib.nameValuePair (lib.strings.removeSuffix ".fish" "${name}") ({
body = builtins.readFile (fishFuncDir + "/${name}");
}))
(lib.attrsets.filterAttrs
(name: type: type == "regular")
(builtins.readDir fishFuncDir)
);
in
{
home-manager.users.djai.programs.fish = {
enable = true;
binds = {
"\cf" = {
command = "forward-char";
mode = "insert";
};
"\ef" = {
command = "forward-word";
mode = "insert";
};
};
shellInit = ''
# start fbterm if in raw tty
if string match -qr "/dev/tty[2-9]" (tty)
fbterm -- env TERM=fbterm tmux new
end
[ -d "$HOME/.cargo/env.fish" ] && source "$HOME/.cargo/env.fish"
'';
interactiveShellInit = ''
fish_vi_key_bindings
starship init fish | source
fish_config theme choose "Catppuccin Macchiato"
if test -n "$TMUX"
ascii.sh
else
if test "$TERM" != "linux"
tmux new
end
end
# make clear also remove scrollback on kitty
[ "(set -q TERM)" -a "$TERM" = "xterm-kitty" ] && alias clear "printf '\033[2J\033[3J\033[1;1H'"
'';
loginShellInit = ''
~/Scripts/diaryEntry.sh > /dev/null # TODO: move to somewhere
'';
shellAbbrs = {
"webcam" = "mpv av://v4l2:/dev/video0 --profile=low-latency --untimed";
"venv" = ". .venv/bin/activate.fish";
"rug" = "sudo openconnect --protocol=gp safenet.vpn.rug.nl";
"dia" = "nvim (date +%F)";
"rm" = "rm -I";
"mv" = "mv -vn";
"make" = "make -j8";
"ll" = "ls -hlav --ignore=..";
"l" = "ls -lav --ignore=.\?\*";
"la" = "ls -A";
"lg" = "lazygit";
"fih" = "fish";
"twi" = "twitch";
"keh" = "kitten icat";
};
# discovered functions + overrides
functions = fishFuncs // {
tmux-updater = fishFuncs.tmux-updater // {onEvent = "fish_preexec";};
histdelete = fishFuncs.histdelete // {onEvent = "fish_postexec";};
};
};
home-manager.users."djai".home.shell.enableFishIntegration = true;
}