MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / buildCommandParts

Function buildCommandParts

source code/utils/bash/bashPipeCommand.ts:121–214  ·  view source on GitHub ↗

* Builds command parts from parsed entries, handling strings and operators. * Special handling for file descriptor redirections to preserve them as single units.

(
  parsed: ParseEntry[],
  start: number,
  end: number,
)

Source from the content-addressed store, hash-verified

119 * Special handling for file descriptor redirections to preserve them as single units.
120 */
121function buildCommandParts(
122 parsed: ParseEntry[],
123 start: number,
124 end: number,
125): string[] {
126 const parts: string[] = []
127 // Track if we've seen a non-env-var string token yet
128 // Environment variables are only valid at the start of a command
129 let seenNonEnvVar = false
130
131 for (let i = start; i < end; i++) {
132 const entry = parsed[i]
133
134 // Check for file descriptor redirections (e.g., 2>&1, 2>/dev/null)
135 if (
136 typeof entry === 'string' &&
137 /^[012]$/.test(entry) &&
138 i + 2 < end &&
139 isOperator(parsed[i + 1])
140 ) {
141 const op = parsed[i + 1] as { op: string }
142 const target = parsed[i + 2]
143
144 // Handle 2>&1 style redirections
145 if (
146 op.op === '>&' &&
147 typeof target === 'string' &&
148 /^[012]$/.test(target)
149 ) {
150 parts.push(`${entry}>&${target}`)
151 i += 2
152 continue
153 }
154
155 // Handle 2>/dev/null style redirections
156 if (op.op === '>' && target === '/dev/null') {
157 parts.push(`${entry}>/dev/null`)
158 i += 2
159 continue
160 }
161
162 // Handle 2> &1 style (space between > and &1)
163 if (
164 op.op === '>' &&
165 typeof target === 'string' &&
166 target.startsWith('&')
167 ) {
168 const fd = target.slice(1)
169 if (/^[012]$/.test(fd)) {
170 parts.push(`${entry}>&${fd}`)
171 i += 2
172 continue
173 }
174 }
175 }
176
177 // Handle regular entries
178 if (typeof entry === 'string') {

Callers 1

rearrangePipeCommandFunction · 0.85

Calls 4

quoteFunction · 0.85
isCommandSeparatorFunction · 0.85
isOperatorFunction · 0.70

Tested by

no test coverage detected