MCPcopy Index your code
hub / github.com/codeaashu/claude-code / createArgv0ShellFunction

Function createArgv0ShellFunction

src/utils/bash/ShellSnapshot.ts:35–59  ·  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

33 * word (no spaces/special chars).
34 */
35function 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)

Callers 2

Calls 1

quoteFunction · 0.85

Tested by

no test coverage detected