nix(feat): Add argbash bash completion support

This commit is contained in:
Wolfgang Walther
2021-04-18 13:51:39 +02:00
committed by Wolfgang Walther
parent c2df7d8198
commit 2559d32912
9 changed files with 113 additions and 68 deletions
@@ -13,6 +13,7 @@
{ name
, docs
, args ? [ ]
, addCommandCompletion ? false
, inRootDir ? false
, redirectTixFiles ? true
, withEnv ? null
@@ -46,6 +47,17 @@ let
runCommand "${name}-parser" { }
"${argbash}/bin/argbash -o $out ${argsTemplate}/${name}.m4";
bashCompletion =
runCommand "${name}-completion" { } (
''
${argbash}/bin/argbash --type completion --strip all ${argsTemplate}/${name}.m4 > $out
''
+ lib.optionalString addCommandCompletion ''
sed 's/COMPREPLY.*compgen -o bashdefault .*$/_command/' -i $out
''
);
bin =
writeTextFile {
inherit name;
@@ -111,4 +123,4 @@ let
script =
runCommand name { inherit bin name; } "ln -s $bin/bin/$name $out";
in
script // { inherit bin; }
script // { inherit bin bashCompletion; }