|
| 1 | +# --- flake-parts/modules/programs/shells/fish.nix |
| 2 | +# |
| 3 | +# Author: tsandrini <tomas.sandrini@seznam.cz> |
| 4 | +# URL: https://github.com/tsandrini/tensorfiles |
| 5 | +# License: MIT |
| 6 | +# |
| 7 | +# 888 .d888 d8b 888 |
| 8 | +# 888 d88P" Y8P 888 |
| 9 | +# 888 888 888 |
| 10 | +# 888888 .d88b. 88888b. .d8888b .d88b. 888d888 888888 888 888 .d88b. .d8888b |
| 11 | +# 888 d8P Y8b 888 "88b 88K d88""88b 888P" 888 888 888 d8P Y8b 88K |
| 12 | +# 888 88888888 888 888 "Y8888b. 888 888 888 888 888 888 88888888 "Y8888b. |
| 13 | +# Y88b. Y8b. 888 888 X88 Y88..88P 888 888 888 888 Y8b. X88 |
| 14 | +# "Y888 "Y8888 888 888 88888P' "Y88P" 888 888 888 888 "Y8888 88888P' |
| 15 | +{ localFlake }: |
| 16 | +{ |
| 17 | + config, |
| 18 | + lib, |
| 19 | + pkgs, |
| 20 | + ... |
| 21 | +}: |
| 22 | +let |
| 23 | + inherit (lib) |
| 24 | + mkIf |
| 25 | + getExe |
| 26 | + mkMerge |
| 27 | + optional |
| 28 | + mkBefore |
| 29 | + mkEnableOption |
| 30 | + mkOption |
| 31 | + types |
| 32 | + ; |
| 33 | + inherit (localFlake.lib.modules) mkOverrideAtHmModuleLevel isModuleLoadedAndEnabled; |
| 34 | + inherit (localFlake.lib.options) mkPywalEnableOption; |
| 35 | + |
| 36 | + cfg = config.tensorfiles.hm.programs.shells.fish; |
| 37 | + _ = mkOverrideAtHmModuleLevel; |
| 38 | +in |
| 39 | +{ |
| 40 | + options.tensorfiles.hm.programs.shells.fish = { |
| 41 | + enable = mkEnableOption '' |
| 42 | + Enables NixOS module that configures/handles the fish shell. |
| 43 | + ''; |
| 44 | + |
| 45 | + pywal = { |
| 46 | + enable = mkPywalEnableOption; |
| 47 | + }; |
| 48 | + |
| 49 | + nixpkgsPlugins = mkOption { |
| 50 | + type = types.listOf types.string; |
| 51 | + default = [ |
| 52 | + "done" |
| 53 | + "grc" |
| 54 | + "foreign-env" |
| 55 | + "colored-man-pages" |
| 56 | + "autopair" |
| 57 | + "sponge" |
| 58 | + "z" |
| 59 | + # "fzf-fish" |
| 60 | + # "forgit" |
| 61 | + ]; |
| 62 | + description = '' |
| 63 | + List of fish plugins from nixpkgs to be installed. |
| 64 | + ''; |
| 65 | + }; |
| 66 | + |
| 67 | + withFzf = mkOption { |
| 68 | + type = types.bool; |
| 69 | + default = true; |
| 70 | + description = '' |
| 71 | + Whether to enable the fzf plugin |
| 72 | + ''; |
| 73 | + }; |
| 74 | + |
| 75 | + shellAliases = { |
| 76 | + lsToEza = mkOption { |
| 77 | + type = types.bool; |
| 78 | + default = true; |
| 79 | + description = '' |
| 80 | + Enable predefined shell aliases |
| 81 | + ''; |
| 82 | + }; |
| 83 | + |
| 84 | + catToBat = mkOption { |
| 85 | + type = types.bool; |
| 86 | + default = true; |
| 87 | + description = '' |
| 88 | + Remap the cat related commands to its reworked edition bat. |
| 89 | + ''; |
| 90 | + }; |
| 91 | + |
| 92 | + findToFd = mkOption { |
| 93 | + type = types.bool; |
| 94 | + default = true; |
| 95 | + description = '' |
| 96 | + Remap the find related commands to its reworked edition fd. |
| 97 | + ''; |
| 98 | + }; |
| 99 | + |
| 100 | + grepToRipgrep = mkOption { |
| 101 | + type = types.bool; |
| 102 | + default = true; |
| 103 | + description = '' |
| 104 | + Remap the find related commands to its reworked edition fd. |
| 105 | + ''; |
| 106 | + }; |
| 107 | + }; |
| 108 | + }; |
| 109 | + |
| 110 | + config = mkIf cfg.enable (mkMerge [ |
| 111 | + # |----------------------------------------------------------------------| # |
| 112 | + { |
| 113 | + home.packages = |
| 114 | + with pkgs; |
| 115 | + with cfg.shellAliases; |
| 116 | + [ |
| 117 | + nitch |
| 118 | + grc |
| 119 | + any-nix-shell |
| 120 | + ] |
| 121 | + ++ (optional lsToEza eza) |
| 122 | + ++ (optional catToBat bat) |
| 123 | + ++ (optional findToFd fd) |
| 124 | + ++ (optional grepToRipgrep ripgrep); |
| 125 | + |
| 126 | + programs.fish = { |
| 127 | + enable = _ true; |
| 128 | + interactiveShellInit = mkBefore '' |
| 129 | + set fish_greeting |
| 130 | +
|
| 131 | + if test -e /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh |
| 132 | + fenv source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh |
| 133 | + end |
| 134 | + if test -e ~/.nix-profile/etc/profile.d/nix.sh |
| 135 | + fenv source ~/.nix-profile/etc/profile.d/nix.sh |
| 136 | + end |
| 137 | + if test -e ~/.nix-profile/etc/profile.d/hm-session-vars.sh |
| 138 | + fenv source ~/.nix-profile/etc/profile.d/hm-session-vars.sh |
| 139 | + end |
| 140 | +
|
| 141 | + ${pkgs.any-nix-shell}/bin/any-nix-shell fish --info-right | source |
| 142 | + ''; |
| 143 | + plugins = |
| 144 | + (optional cfg.withFzf { |
| 145 | + name = "fzf-fish"; |
| 146 | + inherit (pkgs.fishPlugins.fzf-fish) src; |
| 147 | + }) |
| 148 | + ++ (map (_plugin: { |
| 149 | + name = _plugin; |
| 150 | + inherit (pkgs.fishPlugins.${_plugin}) src; |
| 151 | + }) cfg.nixpkgsPlugins); |
| 152 | + }; |
| 153 | + |
| 154 | + programs.starship = { |
| 155 | + enable = _ true; |
| 156 | + # NOTE enabled by default so probably unnecessary |
| 157 | + # enableBashIntegration = _ true; |
| 158 | + # enableFishIntegration = _ true; |
| 159 | + }; |
| 160 | + |
| 161 | + home.shellAliases = mkMerge [ |
| 162 | + { |
| 163 | + fetch = _ "${getExe pkgs.nitch}"; |
| 164 | + g = _ "${getExe config.programs.git.package}"; |
| 165 | + } |
| 166 | + (mkIf cfg.shellAliases.lsToEza { |
| 167 | + ls = _ "${getExe pkgs.eza}"; |
| 168 | + ll = _ "${getExe pkgs.eza} -F --hyperlink --icons --group-directories-first -la --git --header --created --modified"; |
| 169 | + tree = _ "${getExe pkgs.eza} -F --hyperlink --icons --group-directories-first -la --git --header --created --modified -T"; |
| 170 | + }) |
| 171 | + (mkIf cfg.shellAliases.catToBat { |
| 172 | + cat = _ "${getExe pkgs.bat} -p --wrap=never --paging=never"; |
| 173 | + less = _ "${getExe pkgs.bat} --paging=always"; |
| 174 | + }) |
| 175 | + (mkIf cfg.shellAliases.findToFd { |
| 176 | + find = _ "${getExe pkgs.fd}"; |
| 177 | + fd = _ "${getExe pkgs.fd}"; |
| 178 | + }) |
| 179 | + (mkIf cfg.shellAliases.grepToRipgrep { |
| 180 | + grep = _ "${getExe pkgs.ripgrep}"; |
| 181 | + list-todos = _ "${getExe pkgs.ripgrep} -g '!{.git,node_modules,result,build,dist,.idea,out,.DS_Store}' --no-follow 'TODO|FIXME' "; |
| 182 | + }) |
| 183 | + { fetch = _ "${getExe pkgs.nitch}"; } |
| 184 | + ]; |
| 185 | + } |
| 186 | + # |----------------------------------------------------------------------| # |
| 187 | + (mkIf cfg.withFzf { |
| 188 | + programs.fzf = { |
| 189 | + enable = _ true; |
| 190 | + }; |
| 191 | + }) |
| 192 | + # |----------------------------------------------------------------------| # |
| 193 | + (mkIf ((isModuleLoadedAndEnabled config "tensorfiles.hm.programs.pywal") && cfg.pywal.enable) { |
| 194 | + programs.fish.interactiveShellInit = mkBefore '' |
| 195 | + # Import colorscheme from 'wal' asynchronously |
| 196 | + set -l wal_seq (cat ${config.xdg.cacheHome}/wal/sequences)"" |
| 197 | + echo -e $wal_seq & |
| 198 | + ''; |
| 199 | + }) |
| 200 | + # |----------------------------------------------------------------------| # |
| 201 | + (mkIf cfg.shellAliases.catToBat { |
| 202 | + programs.bat = { |
| 203 | + enable = _ true; |
| 204 | + }; |
| 205 | + }) |
| 206 | + # |----------------------------------------------------------------------| # |
| 207 | + (mkIf cfg.shellAliases.grepToRipgrep { |
| 208 | + programs.ripgrep = { |
| 209 | + enable = _ true; |
| 210 | + }; |
| 211 | + }) |
| 212 | + # |----------------------------------------------------------------------| # |
| 213 | + ]); |
| 214 | + |
| 215 | + meta.maintainers = with localFlake.lib.maintainers; [ tsandrini ]; |
| 216 | +} |
0 commit comments