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