1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-01 04:18:00 +02: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:
Tom Bereknyei 2021-08-28 16:26:53 -04:00 committed by tomberek
parent ba4e07782c
commit 74210c12fe
7 changed files with 114 additions and 9 deletions

View file

@ -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; }