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