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

Function getBashCompletionCommand

src/utils/bash/shellCompletion.ts:142–158  ·  view source on GitHub ↗

* Generate bash completion command using compgen

(
  prefix: string,
  completionType: ShellCompletionType,
)

Source from the content-addressed store, hash-verified

140 * Generate bash completion command using compgen
141 */
142function getBashCompletionCommand(
143 prefix: string,
144 completionType: ShellCompletionType,
145): string {
146 if (completionType === 'variable') {
147 // Variable completion - remove $ prefix
148 const varName = prefix.slice(1)
149 return `compgen -v ${quote([varName])} 2>/dev/null`
150 } else if (completionType === 'file') {
151 // File completion with trailing slash for directories and trailing space for files
152 // Use 'while read' to prevent command injection from filenames containing newlines
153 return `compgen -f ${quote([prefix])} 2>/dev/null | head -${MAX_SHELL_COMPLETIONS} | while IFS= read -r f; do [ -d "$f" ] && echo "$f/" || echo "$f "; done`
154 } else {
155 // Command completion
156 return `compgen -c ${quote([prefix])} 2>/dev/null`
157 }
158}
159
160/**
161 * Generate zsh completion command using native zsh commands

Callers 1

getCompletionsForShellFunction · 0.85

Calls 1

quoteFunction · 0.85

Tested by

no test coverage detected