nixos/fish: generate autocompletions from man pages
This commit is contained in:
@@ -169,6 +169,59 @@ 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 (exclusive) / after (inclusive) 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
|
||||
patchedGenerator = pkgs.stdenv.mkDerivation {
|
||||
name = "fish_patched-completion-generator";
|
||||
srcs = [
|
||||
"${pkgs.fish}/share/fish/tools/create_manpage_completions.py"
|
||||
"${pkgs.fish}/share/fish/tools/deroff.py"
|
||||
];
|
||||
unpackCmd = "cp $curSrc $(basename $curSrc)";
|
||||
sourceRoot = ".";
|
||||
patches = [ ./fish_completion-generator.patch ]; # to prevent collisions of identical completion files
|
||||
dontBuild = true;
|
||||
installPhase = ''
|
||||
mkdir -p $out
|
||||
cp * $out/
|
||||
'';
|
||||
preferLocalBuild = true;
|
||||
allowSubstitutes = false;
|
||||
};
|
||||
generateCompletions = package: pkgs.runCommand
|
||||
"${package.name}_fish-completions"
|
||||
(
|
||||
{
|
||||
inherit package;
|
||||
preferLocalBuild = true;
|
||||
allowSubstitutes = false;
|
||||
}
|
||||
// optionalAttrs (package ? meta.priority) { meta.priority = package.meta.priority; }
|
||||
)
|
||||
''
|
||||
mkdir -p $out
|
||||
if [ -d $package/share/man ]; then
|
||||
find $package/share/man -type f | xargs ${pkgs.python3.interpreter} ${patchedGenerator}/create_manpage_completions.py --directory $out >/dev/null
|
||||
fi
|
||||
'';
|
||||
in
|
||||
pkgs.buildEnv {
|
||||
name = "system_fish-completions";
|
||||
ignoreCollisions = true;
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user