nix(feat): Add bash completion for git references
This commit is contained in:
committed by
Wolfgang Walther
parent
32ff9dfb48
commit
5a8d9b1246
@@ -14,7 +14,7 @@
|
||||
{ name
|
||||
, docs
|
||||
, args ? [ ]
|
||||
, addCommandCompletion ? false
|
||||
, positionalCompletion ? ""
|
||||
, inRootDir ? false
|
||||
, redirectTixFiles ? true
|
||||
, withEnv ? null
|
||||
@@ -22,11 +22,10 @@
|
||||
, withTmpDir ? false
|
||||
}: text:
|
||||
let
|
||||
# square brackets are a pain to escape - if even possible. just don't use them...
|
||||
escape = builtins.replaceStrings [ "\n" ] [ " \\n" ];
|
||||
|
||||
argsTemplate =
|
||||
let
|
||||
# square brackets are a pain to escape - if even possible. just don't use them...
|
||||
escapedDocs = builtins.replaceStrings [ "\n" ] [ " \\n" ] docs;
|
||||
in
|
||||
writeTextFile {
|
||||
inherit name;
|
||||
destination = "/${name}.m4"; # destination is needed to have the proper basename for completion
|
||||
@@ -37,7 +36,7 @@ let
|
||||
# stripping the /nix/store/... path for nicer display
|
||||
BASH_ARGV0="$(basename "$0")"
|
||||
|
||||
# ARG_HELP([${name}], [${escapedDocs}])
|
||||
# ARG_HELP([${name}], [${escape docs}])
|
||||
${lib.strings.concatMapStrings (arg: "# " + arg) args}
|
||||
# ARG_POSITIONAL_DOUBLEDASH()
|
||||
# ARG_DEFAULTS_POS()
|
||||
@@ -65,8 +64,8 @@ let
|
||||
${argbash}/bin/argbash --type completion --strip all ${argsTemplate}/${name}.m4 > $out
|
||||
''
|
||||
|
||||
+ lib.optionalString addCommandCompletion ''
|
||||
sed 's/COMPREPLY.*compgen -o bashdefault .*$/_command/' -i $out
|
||||
+ lib.optionalString (positionalCompletion != "") ''
|
||||
sed 's#COMPREPLY.*compgen -o bashdefault .*$#${escape positionalCompletion}#' -i $out
|
||||
''
|
||||
);
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ let
|
||||
"ARG_POSITIONAL_SINGLE([command], [Command to run])"
|
||||
"ARG_LEFTOVERS([command arguments])"
|
||||
];
|
||||
addCommandCompletion = true;
|
||||
positionalCompletion = "_command";
|
||||
redirectTixFiles = false; # will be done by sub-command
|
||||
inRootDir = true;
|
||||
}
|
||||
|
||||
+10
-1
@@ -61,9 +61,12 @@ let
|
||||
'';
|
||||
|
||||
loadtestAgainst =
|
||||
let
|
||||
name = "postgrest-loadtest-against";
|
||||
in
|
||||
checkedShellScript
|
||||
{
|
||||
name = "postgrest-loadtest-against";
|
||||
inherit name;
|
||||
docs =
|
||||
''
|
||||
Run the vegeta loadtest twice:
|
||||
@@ -74,6 +77,12 @@ let
|
||||
"ARG_POSITIONAL_SINGLE([target], [Commit-ish reference to compare with])"
|
||||
"ARG_LEFTOVERS([additional vegeta arguments])"
|
||||
];
|
||||
positionalCompletion =
|
||||
''
|
||||
if test "$prev" == "${name}"; then
|
||||
__gitcomp_nl "$(__git_refs)"
|
||||
fi
|
||||
'';
|
||||
inRootDir = true;
|
||||
}
|
||||
''
|
||||
|
||||
+15
-5
@@ -27,7 +27,7 @@ let
|
||||
"ARG_USE_ENV([PGRST_DB_SCHEMAS], [test], [Schema to expose])"
|
||||
"ARG_USE_ENV([PGRST_DB_ANON_ROLE], [postgrest_test_anonymous], [Anonymous PG role])"
|
||||
];
|
||||
addCommandCompletion = true;
|
||||
positionalCompletion = "_command";
|
||||
inRootDir = true;
|
||||
redirectTixFiles = false;
|
||||
withPath = [ postgresql ];
|
||||
@@ -118,7 +118,7 @@ let
|
||||
"ARG_POSITIONAL_SINGLE([command], [Command to run])"
|
||||
"ARG_LEFTOVERS([command arguments])"
|
||||
];
|
||||
addCommandCompletion = true;
|
||||
positionalCompletion = "_command";
|
||||
inRootDir = true;
|
||||
}
|
||||
(lib.concatStringsSep "\n\n" runners);
|
||||
@@ -129,9 +129,12 @@ let
|
||||
withPg = builtins.head withPgVersions;
|
||||
|
||||
withGit =
|
||||
let
|
||||
name = "postgrest-with-git";
|
||||
in
|
||||
checkedShellScript
|
||||
{
|
||||
name = "postgrest-with-git";
|
||||
inherit name;
|
||||
docs =
|
||||
''
|
||||
Create a new worktree of the postgrest repo in a temporary directory and
|
||||
@@ -143,7 +146,14 @@ let
|
||||
"ARG_POSITIONAL_SINGLE([command], [Command to run])"
|
||||
"ARG_LEFTOVERS([command arguments])"
|
||||
];
|
||||
addCommandCompletion = true; # TODO: first positional argument needs git commit completion
|
||||
positionalCompletion =
|
||||
''
|
||||
if test "$prev" == "${name}"; then
|
||||
__gitcomp_nl "$(__git_refs)"
|
||||
else
|
||||
_command_offset 2
|
||||
fi
|
||||
'';
|
||||
inRootDir = true;
|
||||
}
|
||||
''
|
||||
@@ -229,7 +239,7 @@ let
|
||||
"ARG_POSITIONAL_SINGLE([command], [Command to run])"
|
||||
"ARG_LEFTOVERS([command arguments])"
|
||||
];
|
||||
addCommandCompletion = true;
|
||||
positionalCompletion = "_command";
|
||||
inRootDir = true;
|
||||
withEnv = postgrest.env;
|
||||
withTmpDir = true;
|
||||
|
||||
@@ -38,6 +38,7 @@ lib.overrideDerivation postgrest.env (
|
||||
base.buildInputs ++ [
|
||||
pkgs.cabal-install
|
||||
pkgs.cabal2nix
|
||||
pkgs.git
|
||||
pkgs.postgresql
|
||||
postgrest.hsie.bin
|
||||
]
|
||||
@@ -46,6 +47,7 @@ lib.overrideDerivation postgrest.env (
|
||||
shellHook =
|
||||
''
|
||||
source ${pkgs.bashCompletion}/etc/profile.d/bash_completion.sh
|
||||
source ${pkgs.git}/share/git/contrib/completion/git-completion.bash
|
||||
source ${postgrest.hsie.bashCompletion}
|
||||
|
||||
''
|
||||
|
||||
Reference in New Issue
Block a user