mirror of
https://github.com/NixOS/nix.git
synced 2025-11-13 14:02:42 +01:00
Shellbang support with flakes
Enables shebang usage of nix shell. All arguments with `#! nix` get
added to the nix invocation. This implementation does NOT set any
additional arguments other than placing the script path itself as the
first argument such that the interpreter can utilize it.
Example below:
```
#!/usr/bin/env nix
#! nix shell --quiet
#! nix nixpkgs#bash
#! nix nixpkgs#shellcheck
#! nix nixpkgs#hello
#! nix --ignore-environment --command bash
# shellcheck shell=bash
set -eu
shellcheck "$0" || exit 1
function main {
hello
echo 0:"$0" 1:"$1" 2:"$2"
}
"$@"
```
fix: include programName usage
EDIT: For posterity I've changed shellwords to shellwords2 in order
not to interfere with other changes during a rebase.
shellwords2 is removed in a later commit. -- roberth
This commit is contained in:
parent
ba4e07782c
commit
74210c12fe
7 changed files with 114 additions and 9 deletions
|
|
@ -27,8 +27,14 @@ class Args
|
|||
public:
|
||||
|
||||
/**
|
||||
* Return a short one-line description of the command.
|
||||
* Parse the command line with argv0, throwing a UsageError if something
|
||||
goes wrong.
|
||||
*/
|
||||
void parseCmdline(const std::string & argv0, const Strings & cmdline);
|
||||
|
||||
/**
|
||||
* Return a short one-line description of the command.
|
||||
*/
|
||||
virtual std::string description() { return ""; }
|
||||
|
||||
virtual bool forceImpureByDefault() { return false; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue