MCPcopy Create free account
hub / github.com/Noumena-Network/code / createArgv0ShellFunction

Function createArgv0ShellFunction

src/utils/bash/ShellSnapshot.ts:36–60  ·  view source on GitHub ↗

* 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[] = [],
)

Source from the content-addressed store, hash-verified

34 * word (no spaces/special chars).
35 */
36function createArgv0ShellFunction(
37 funcName: string,
38 argv0: string,
39 binaryPath: string,
40 prependArgs: string[] = [],
41): string {
42 const quotedPath = quote([binaryPath])
43 const argSuffix =
44 prependArgs.length > 0 ? `${prependArgs.join(' ')} "$@"` : '"$@"'
45 return [
46 `function ${funcName} {`,
47 ' if [[ -n $ZSH_VERSION ]]; then',
48 ` ARGV0=${argv0} ${quotedPath} ${argSuffix}`,
49 ' elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then',
50 // On Windows (git bash), exec -a does not work, so use ARGV0 env var instead
51 // The bun binary reads from ARGV0 natively to set argv[0]
52 ` ARGV0=${argv0} ${quotedPath} ${argSuffix}`,
53 ' elif [[ $BASHPID != $$ ]]; then',
54 ` exec -a ${argv0} ${quotedPath} ${argSuffix}`,
55 ' else',
56 ` (exec -a ${argv0} ${quotedPath} ${argSuffix})`,
57 ' fi',
58 '}',
59 ].join('\n')
60}
61
62/**
63 * Creates ripgrep shell integration (alias or function)

Callers 2

Calls 1

quoteFunction · 0.85

Tested by

no test coverage detected