diff options
author | Linus Heckemann <git@sphalerite.org> | 2019-02-25 22:03:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-25 22:03:51 +0100 |
commit | 31f0972e2715f3bab3779a70d964463505e4574f (patch) | |
tree | 63df1682acd1eb4a5f8a5635ad1be8cec5ac2b37 /nixos/modules | |
parent | cedd8bfa0e5c230d6e3677737e4a7715d1f0bd87 (diff) | |
parent | 5cc63776472effb04ad3a472e48e37577243c133 (diff) |
Merge pull request #52464 from hyperfekt/fish_generate-completions
nixos/fish: generate autocompletions from man pages
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/programs/fish.nix | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/nixos/modules/programs/fish.nix b/nixos/modules/programs/fish.nix index b38af07b92c3..03d6c26c8c87 100644 --- a/nixos/modules/programs/fish.nix +++ b/nixos/modules/programs/fish.nix @@ -169,6 +169,43 @@ in end ''; + programs.fish.interactiveShellInit = '' + # add completions generated by NixOS to $fish_complete_path + begin + # joins with null byte to acommodate all characters in paths, then respectively gets all paths before / after the first one including "generated_completions", + # splits by null byte, and then removes all empty lines produced by using 'string' + set -l prev (string join0 $fish_complete_path | string match --regex "^.*?(?=\x00[^\x00]*generated_completions.*)" | string split0 | string match -er ".") + set -l post (string join0 $fish_complete_path | string match --regex "[^\x00]*generated_completions.*" | string split0 | string match -er ".") + set fish_complete_path $prev "/etc/fish/generated_completions" $post + end + ''; + + environment.etc."fish/generated_completions".source = + let + generateCompletions = package: pkgs.runCommand + "${package.name}-fish-completions" + ( + { + src = package; + nativeBuildInputs = [ pkgs.python3 ]; + buildInputs = [ pkgs.fish ]; + preferLocalBuild = true; + allowSubstitutes = false; + } + // optionalAttrs (package ? meta.priority) { meta.priority = package.meta.priority; } + ) + '' + mkdir -p $out + if [ -d $src/share/man ]; then + find $src/share/man -type f | xargs python ${pkgs.fish}/share/fish/tools/create_manpage_completions.py --directory $out >/dev/null + fi + ''; + in + pkgs.buildEnv { + name = "system-fish-completions"; + paths = map generateCompletions config.environment.systemPackages; + }; + # include programs that bring their own completions environment.pathsToLink = [] ++ optional cfg.vendor.config.enable "/share/fish/vendor_conf.d" |