mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 15:56:18 +02:00
nix dev-shell: Add --command option
Note: like 'nix run', and unlike 'nix-shell', this takes an argv vector rather than a shell command. So nix dev-shell -c 'echo $PATH' doesn't work. Instead you need to do nix dev-shell -c bash -c 'echo $PATH'
This commit is contained in:
parent
7cd9859e41
commit
2672a28bb4
1 changed files with 23 additions and 0 deletions
|
@ -232,6 +232,22 @@ struct Common : InstallableCommand, MixProfile
|
|||
|
||||
struct CmdDevShell : Common, MixEnvironment
|
||||
{
|
||||
std::vector<std::string> command;
|
||||
|
||||
CmdDevShell()
|
||||
{
|
||||
mkFlag()
|
||||
.longName("command")
|
||||
.shortName('c')
|
||||
.description("command and arguments to be executed insted of an interactive shell")
|
||||
.labels({"command", "args"})
|
||||
.arity(ArityAny)
|
||||
.handler([&](std::vector<std::string> ss) {
|
||||
if (ss.empty()) throw UsageError("--command requires at least one argument");
|
||||
command = ss;
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "run a bash shell that provides the build environment of a derivation";
|
||||
|
@ -270,6 +286,13 @@ struct CmdDevShell : Common, MixEnvironment
|
|||
|
||||
ss << fmt("rm -f '%s'\n", rcFilePath);
|
||||
|
||||
if (!command.empty()) {
|
||||
std::vector<std::string> args;
|
||||
for (auto s : command)
|
||||
args.push_back(shellEscape(s));
|
||||
ss << fmt("exec %s\n", concatStringsSep(" ", args));
|
||||
}
|
||||
|
||||
writeFull(rcFileFd.get(), ss.str());
|
||||
|
||||
stopProgressBar();
|
||||
|
|
Loading…
Reference in a new issue