MCPcopy
hub / github.com/codeaashu/claude-code / getZshCompletionCommand

Function getZshCompletionCommand

src/utils/bash/shellCompletion.ts:163–179  ·  view source on GitHub ↗

* Generate zsh completion command using native zsh commands

(
  prefix: string,
  completionType: ShellCompletionType,
)

Source from the content-addressed store, hash-verified

161 * Generate zsh completion command using native zsh commands
162 */
163function getZshCompletionCommand(
164 prefix: string,
165 completionType: ShellCompletionType,
166): string {
167 if (completionType === 'variable') {
168 // Variable completion - use zsh pattern matching for safe filtering
169 const varName = prefix.slice(1)
170 return `print -rl -- \${(k)parameters[(I)${quote([varName])}*]} 2>/dev/null`
171 } else if (completionType === 'file') {
172 // File completion with trailing slash for directories and trailing space for files
173 // Note: zsh glob expansion is safe from command injection (unlike bash for-in loops)
174 return `for f in ${quote([prefix])}*(N[1,${MAX_SHELL_COMPLETIONS}]); do [[ -d "$f" ]] && echo "$f/" || echo "$f "; done`
175 } else {
176 // Command completion - use zsh pattern matching for safe filtering
177 return `print -rl -- \${(k)commands[(I)${quote([prefix])}*]} 2>/dev/null`
178 }
179}
180
181/**
182 * Get completions for the given shell type

Callers 1

getCompletionsForShellFunction · 0.85

Calls 1

quoteFunction · 0.85

Tested by

no test coverage detected