fork/home-manager

git clone https://git.julia.blue/fork/home-manager

XYenonyazi: add fish and nushell integration7413408b

master
4.3 KiB165 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6  cfg = config.programs.yazi;
7  tomlFormat = pkgs.formats.toml { };
8
9  bashIntegration = ''
10    function ya() {
11      tmp="$(mktemp -t "yazi-cwd.XXXXX")"
12      yazi --cwd-file="$tmp"
13      if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
14        cd -- "$cwd"
15      fi
16      rm -f -- "$tmp"
17    }
18  '';
19
20  fishIntegration = ''
21    function ya
22      set tmp (mktemp -t "yazi-cwd.XXXXX")
23      yazi --cwd-file="$tmp"
24      if set cwd (cat -- "$tmp") && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]
25        cd -- "$cwd"
26      end
27      rm -f -- "$tmp"
28    end
29  '';
30
31  nushellIntegration = ''
32    def-env ya [] {
33      let tmp = (mktemp -t "yazi-cwd.XXXXX")
34      yazi --cwd-file $tmp
35      let cwd = (cat -- $tmp)
36      if $cwd != "" and $cwd != $env.PWD {
37        cd $cwd
38      }
39      rm -f $tmp
40    }
41  '';
42in {
43  meta.maintainers = [ maintainers.xyenon ];
44
45  options.programs.yazi = {
46    enable = mkEnableOption "yazi";
47
48    package = mkOption {
49      type = types.package;
50      default = pkgs.yazi;
51      defaultText = literalExpression "pkgs.yazi";
52      description = "Yazi package to install.";
53    };
54
55    enableBashIntegration = mkEnableOption "Bash integration";
56
57    enableZshIntegration = mkEnableOption "Zsh integration";
58
59    enableFishIntegration = mkEnableOption "Fish integration";
60
61    enableNushellIntegration = mkEnableOption "Nushell integration";
62
63    keymap = mkOption {
64      type = tomlFormat.type;
65      default = { };
66      example = literalExpression ''
67        {
68          input.keymap = [
69            { exec = "close"; on = [ "<C-q>" ]; }
70            { exec = "close --submit"; on = [ "<Enter>" ]; }
71            { exec = "escape"; on = [ "<Esc>" ]; }
72            { exec = "backspace"; on = [ "<Backspace>" ]; }
73          ];
74          manager.keymap = [
75            { exec = "escape"; on = [ "<Esc>" ]; }
76            { exec = "quit"; on = [ "q" ]; }
77            { exec = "close"; on = [ "<C-q>" ]; }
78          ];
79        }
80      '';
81      description = ''
82        Configuration written to
83        {file}`$XDG_CONFIG_HOME/yazi/keymap.toml`.
84
85        See <https://github.com/sxyazi/yazi/blob/main/config/docs/keymap.md>
86        for the full list of options.
87      '';
88    };
89
90    settings = mkOption {
91      type = tomlFormat.type;
92      default = { };
93      example = literalExpression ''
94        {
95          log = {
96            enabled = false;
97          };
98          manager = {
99            show_hidden = false;
100            sort_by = "modified";
101            sort_dir_first = true;
102            sort_reverse = true;
103          };
104        }
105      '';
106      description = ''
107        Configuration written to
108        {file}`$XDG_CONFIG_HOME/yazi/yazi.toml`.
109
110        See <https://github.com/sxyazi/yazi/blob/main/config/docs/yazi.md>
111        for the full list of options.
112      '';
113    };
114
115    theme = mkOption {
116      type = tomlFormat.type;
117      default = { };
118      example = literalExpression ''
119        {
120          filetype = {
121            rules = [
122              { fg = "#7AD9E5"; mime = "image/*"; }
123              { fg = "#F3D398"; mime = "video/*"; }
124              { fg = "#F3D398"; mime = "audio/*"; }
125              { fg = "#CD9EFC"; mime = "application/x-bzip"; }
126            ];
127          };
128        }
129      '';
130      description = ''
131        Configuration written to
132        {file}`$XDG_CONFIG_HOME/yazi/theme.toml`.
133
134        See <https://github.com/sxyazi/yazi/blob/main/config/docs/theme.md>
135        for the full list of options
136      '';
137    };
138  };
139
140  config = mkIf cfg.enable {
141    home.packages = [ cfg.package ];
142
143    programs.bash.initExtra = mkIf cfg.enableBashIntegration bashIntegration;
144
145    programs.zsh.initExtra = mkIf cfg.enableZshIntegration bashIntegration;
146
147    programs.fish.interactiveShellInit =
148      mkIf cfg.enableFishIntegration fishIntegration;
149
150    programs.nushell.extraConfig =
151      mkIf cfg.enableNushellIntegration nushellIntegration;
152
153    xdg.configFile = {
154      "yazi/keymap.toml" = mkIf (cfg.keymap != { }) {
155        source = tomlFormat.generate "yazi-keymap" cfg.keymap;
156      };
157      "yazi/yazi.toml" = mkIf (cfg.settings != { }) {
158        source = tomlFormat.generate "yazi-settings" cfg.settings;
159      };
160      "yazi/theme.toml" = mkIf (cfg.theme != { }) {
161        source = tomlFormat.generate "yazi-theme" cfg.theme;
162      };
163    };
164  };
165}