* Creates a shell function that invokes `binaryPath` with a specific argv[0]. * This uses the bun-internal ARGV0 dispatch trick: the bun binary checks its * argv[0] and runs the embedded tool (rg, bfs, ugrep) that matches. * * @param prependArgs - Arguments to inject before the user's args (e.g.
( funcName: string, argv0: string, binaryPath: string, prependArgs: string[] = [], )
| 33 | * word (no spaces/special chars). |
| 34 | */ |
| 35 | function createArgv0ShellFunction( |
| 36 | funcName: string, |
| 37 | argv0: string, |
| 38 | binaryPath: string, |
| 39 | prependArgs: string[] = [], |
| 40 | ): string { |
| 41 | const quotedPath = quote([binaryPath]) |
| 42 | const argSuffix = |
| 43 | prependArgs.length > 0 ? `${prependArgs.join(' ')} "$@"` : '"$@"' |
| 44 | return [ |
| 45 | `function ${funcName} {`, |
| 46 | ' if [[ -n $ZSH_VERSION ]]; then', |
| 47 | ` ARGV0=${argv0} ${quotedPath} ${argSuffix}`, |
| 48 | ' elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then', |
| 49 | // On Windows (git bash), exec -a does not work, so use ARGV0 env var instead |
| 50 | // The bun binary reads from ARGV0 natively to set argv[0] |
| 51 | ` ARGV0=${argv0} ${quotedPath} ${argSuffix}`, |
| 52 | ' elif [[ $BASHPID != $$ ]]; then', |
| 53 | ` exec -a ${argv0} ${quotedPath} ${argSuffix}`, |
| 54 | ' else', |
| 55 | ` (exec -a ${argv0} ${quotedPath} ${argSuffix})`, |
| 56 | ' fi', |
| 57 | '}', |
| 58 | ].join('\n') |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Creates ripgrep shell integration (alias or function) |
no test coverage detected