From 546ee5f9658d171d76352dc871448ef4a54d7ccf Mon Sep 17 00:00:00 2001 From: ooks-io Date: Mon, 15 Jul 2024 12:37:19 +1200 Subject: [PATCH] refactor(home:fish): split config --- home/modules/console/shell/fish/aliases.nix | 26 +++++++++++++++ home/modules/console/shell/fish/binds.nix | 18 +++++++++++ home/modules/console/shell/fish/default.nix | 36 ++++++--------------- home/modules/console/shell/fish/plugins.nix | 29 +++++++++++++++++ hosts/ookst480s/default.nix | 2 +- 5 files changed, 83 insertions(+), 28 deletions(-) create mode 100644 home/modules/console/shell/fish/aliases.nix create mode 100644 home/modules/console/shell/fish/binds.nix create mode 100644 home/modules/console/shell/fish/plugins.nix diff --git a/home/modules/console/shell/fish/aliases.nix b/home/modules/console/shell/fish/aliases.nix new file mode 100644 index 0000000..c44691b --- /dev/null +++ b/home/modules/console/shell/fish/aliases.nix @@ -0,0 +1,26 @@ +{ lib, config, osConfig, pkgs, ... }: + +let + inherit (lib) mkIf getExe; + inherit (pkgs) bat eza dust; + + cfg = config.ooknet.shell.fish; + admin = osConfig.ooknet.host.admin; +in + +{ + config = mkIf (cfg.enable || admin.shell == "fish") { + programs.fish = { + shellAliases = { + cat = "${getExe bat}"; + ls = "${getExe eza} -a --icons --group-directories-first"; + lst = "${getExe eza} -T -L 5 --icons --group-directories-first"; + du = "${getExe dust}"; + }; + shellAbbrs = { + f = "cd $FLAKE"; + fe = "$EDITOR $FLAKE"; + }; + }; + }; +} diff --git a/home/modules/console/shell/fish/binds.nix b/home/modules/console/shell/fish/binds.nix new file mode 100644 index 0000000..9d0492d --- /dev/null +++ b/home/modules/console/shell/fish/binds.nix @@ -0,0 +1,18 @@ +{ lib, config, osConfig, ... }: + +let + inherit (lib) mkIf; + cfg = config.ooknet.shell.fish; + admin = osConfig.ooknet.host.admin; +in + +{ + config = mkIf (cfg.enable || admin.shell == "fish") { + programs.fish.functions = { + fish_user_key_bindings = '' + bind --preset -M insert \cf fe + bind --preset -M insert \ec fzf_cd_widget + ''; + }; + }; +} diff --git a/home/modules/console/shell/fish/default.nix b/home/modules/console/shell/fish/default.nix index 8b67a89..efc9181 100644 --- a/home/modules/console/shell/fish/default.nix +++ b/home/modules/console/shell/fish/default.nix @@ -1,41 +1,23 @@ { lib, config, osConfig, ... }: + let - inherit (lib) mkIf any; + inherit (lib) mkIf; cfg = config.ooknet.shell.fish; admin = osConfig.ooknet.host.admin; - hasPackage = pname: any (p: p ? pname && p.pname == pname) config.home.packages; - hasEza = hasPackage "eza"; - hasBat = hasPackage "bat"; in + { + imports = [ + ./plugins.nix + ./binds.nix + ./aliases.nix + ]; + config = mkIf (cfg.enable || admin.shell == "fish") { programs.fish = { enable = true; - shellAbbrs = { - fe = "cd $FLAKE; $EDITOR $FLAKE"; - f = "cd $FLAKE"; - s = "cd $SCRIPTS"; - tree = mkIf hasEza "eza -T --icons --group-directories-first"; - ls = mkIf hasEza "eza -a --icons --group-directories-first"; - lsd = mkIf hasEza "eza -al --icons --group-directories-first"; - lst = mkIf hasEza "eza -T -L 5 --icons --group-directories-first"; - lsta = mkIf hasEza "eza -T --icons --group-directories-first"; - cat = mkIf hasBat "bat"; - }; functions = { fish_greeting = ""; - fish_flake_edit = '' - cd $FLAKE - hx $FLAKE - ''; - fish_hello_world = '' - echo "Hello World"; string repeat -N \n --count=(math (count (fish_prompt)) - 1); commandline -f repaint - ''; - - fish_user_key_bindings = '' - bind --preset -M insert \cf fish_flake_edit - bind --preset -M insert \ec fzf_cd_widget - ''; }; interactiveShellInit = # Use vim bindings and cursors diff --git a/home/modules/console/shell/fish/plugins.nix b/home/modules/console/shell/fish/plugins.nix new file mode 100644 index 0000000..0cafc74 --- /dev/null +++ b/home/modules/console/shell/fish/plugins.nix @@ -0,0 +1,29 @@ +{ lib, config, pkgs, osConfig, ... }: + +let + inherit (lib) mkIf; + cfg = config.ooknet.shell.fish; + admin = osConfig.ooknet.host.admin; +in + +{ + config = mkIf (cfg.enable || admin.shell == "fish") { + programs.fish = { + plugins = [ + { + name = "done"; + src = pkgs.fishPlugins.done.src; + } + { + name = "autopair"; + src = pkgs.fishPlugins.autopair.src; + } + { + name = "colored-man-pages"; + src = pkgs.fishPlugins.colored-man-pages.src; + } + ]; + }; + }; +} + diff --git a/hosts/ookst480s/default.nix b/hosts/ookst480s/default.nix index 1224bb3..957e13d 100644 --- a/hosts/ookst480s/default.nix +++ b/hosts/ookst480s/default.nix @@ -17,7 +17,7 @@ in profiles = [ "console-tools" "media" ]; admin = { name = "ooks"; - shell = "zsh"; + shell = "fish"; homeManager = true; }; networking = {