···2727 # The lessopen package pulls in Perl.
2828 less.lessopen = mkDefault null;
2929 command-not-found.enable = mkDefault false;
3030+ fish.generateCompletions = mkDefault false;
3031 };
31323233 # This pulls in nixos-containers which depends on Perl.
+24-16
nixos/modules/programs/fish.nix
···7272 '';
7373 };
74747575+ generateCompletions = lib.mkEnableOption "generating completion files from man pages" // {
7676+ default = true;
7777+ example = false;
7878+ };
7979+7580 vendor.config.enable = lib.mkOption {
7681 type = lib.types.bool;
7782 default = true;
···247252 '';
248253 }
249254250250- {
255255+ (lib.mkIf cfg.generateCompletions {
251256 etc."fish/generated_completions".source =
252257 let
253258 patchedGenerator = pkgs.stdenv.mkDerivation {
···297302 ignoreCollisions = true;
298303 paths = builtins.map generateCompletions config.environment.systemPackages;
299304 };
300300- }
305305+ })
301306302307 # include programs that bring their own completions
303308 {
···318323 }
319324 ];
320325321321- programs.fish.interactiveShellInit = ''
322322- # add completions generated by NixOS to $fish_complete_path
323323- begin
324324- # joins with null byte to accommodate all characters in paths, then respectively gets all paths before (exclusive) / after (inclusive) the first one including "generated_completions",
325325- # splits by null byte, and then removes all empty lines produced by using 'string'
326326- set -l prev (string join0 $fish_complete_path | string match --regex "^.*?(?=\x00[^\x00]*generated_completions.*)" | string split0 | string match -er ".")
327327- set -l post (string join0 $fish_complete_path | string match --regex "[^\x00]*generated_completions.*" | string split0 | string match -er ".")
328328- set fish_complete_path $prev "/etc/fish/generated_completions" $post
329329- end
330330- # prevent fish from generating completions on first run
331331- if not test -d $__fish_user_data_dir/generated_completions
332332- ${pkgs.coreutils}/bin/mkdir $__fish_user_data_dir/generated_completions
333333- end
334334- '';
326326+ programs.fish.interactiveShellInit =
327327+ lib.optionalString cfg.generateCompletions ''
328328+ # add completions generated by NixOS to $fish_complete_path
329329+ begin
330330+ # joins with null byte to accommodate all characters in paths, then respectively gets all paths before (exclusive) / after (inclusive) the first one including "generated_completions",
331331+ # splits by null byte, and then removes all empty lines produced by using 'string'
332332+ set -l prev (string join0 $fish_complete_path | string match --regex "^.*?(?=\x00[^\x00]*generated_completions.*)" | string split0 | string match -er ".")
333333+ set -l post (string join0 $fish_complete_path | string match --regex "[^\x00]*generated_completions.*" | string split0 | string match -er ".")
334334+ set fish_complete_path $prev "/etc/fish/generated_completions" $post
335335+ end
336336+ ''
337337+ + ''
338338+ # prevent fish from generating completions on first run
339339+ if not test -d $__fish_user_data_dir/generated_completions
340340+ ${pkgs.coreutils}/bin/mkdir $__fish_user_data_dir/generated_completions
341341+ end
342342+ '';
335343336344 };
337345 meta.maintainers = with lib.maintainers; [ sigmasquadron ];