* Generate bash completion command using compgen
( prefix: string, completionType: ShellCompletionType, )
| 140 | * Generate bash completion command using compgen |
| 141 | */ |
| 142 | function 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 |
no test coverage detected