Skip to main content

bash_exec

Function bash_exec 

Source
pub fn bash_exec(command: &str) -> i32
Expand description

Execute a command through bash with streaming output, then print environment changes as fish commands to stdout.

Returns the bash command’s exit code. The caller (fish) is expected to pipe stdout through | source to apply environment changes.

How it works:

  1. Capture a “before” snapshot of the current environment
  2. Run the command in bash with stderr inherited (streams directly)
  3. Stdout is captured — the command output appears before our markers, and we print it back to the real stdout immediately
  4. After the markers, we parse the env dump
  5. Diff before/after and print fish set commands

§Examples

use reef::passthrough::bash_exec;

// Run a bash command and get its exit code
let exit_code = bash_exec("export MY_VAR=hello && echo done");
assert_eq!(exit_code, 0);
// Fish `set -gx MY_VAR hello` commands are printed to stdout