File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
modules/capture-foreign-env Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ # Returns a record of changed env variables after running a non-nushell script's contents (passed via stdin), e.g. a bash script you want to "source"
2+ export def main [
3+ -- shell (- s ): string = /bin/sh
4+ # The shell to run the script in
5+ # (has to support '-c' argument and POSIX 'env', 'echo', 'eval' commands)
6+ -- arguments (- a ): list <string > = []
7+ # Additional command line arguments to pass to the foreign shell
8+ ] {
9+ let script_contents = $in ;
10+ let env_out = with-env { SCRIPT_TO_SOURCE : $script_contents } {
11+ ^$shell ... $arguments -c `
12+ env -0
13+ echo -n '<ENV_CAPTURE_EVAL_FENCE>'
14+ eval "$SCRIPT_TO_SOURCE"
15+ echo -n '<ENV_CAPTURE_EVAL_FENCE>'
16+ env -0 -u _ -u _AST_FEATURES -u SHLVL`
17+ }
18+ | split row ' <ENV_CAPTURE_EVAL_FENCE>'
19+ | {
20+ before : ($in | first | str trim -- char (char nul ) | split row (char nul ))
21+ after : ($in | last | str trim -- char (char nul ) | split row (char nul ))
22+ }
23+
24+ $env_out.after
25+ | where { |line | $line not-in $env_out.before }
26+ | parse " {key}={value}"
27+ | transpose -- header-row -- as-record
28+ }
You can’t perform that action at this time.
0 commit comments