| 146 | * @returns The formatted replacement value |
| 147 | */ |
| 148 | export function formatReplacementValue(options: { |
| 149 | displayText: string; |
| 150 | mode: string; |
| 151 | hasAtPrefix: boolean; |
| 152 | needsQuotes: boolean; |
| 153 | isQuoted?: boolean; |
| 154 | isComplete: boolean; |
| 155 | }): string { |
| 156 | const { |
| 157 | displayText, |
| 158 | mode, |
| 159 | hasAtPrefix, |
| 160 | needsQuotes, |
| 161 | isQuoted, |
| 162 | isComplete |
| 163 | } = options; |
| 164 | const space = isComplete ? ' ' : ''; |
| 165 | if (isQuoted || needsQuotes) { |
| 166 | // Use quoted format |
| 167 | return mode === 'bash' ? `"${displayText}"${space}` : `@"${displayText}"${space}`; |
| 168 | } else if (hasAtPrefix) { |
| 169 | return mode === 'bash' ? `${displayText}${space}` : `@${displayText}${space}`; |
| 170 | } else { |
| 171 | return displayText; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Apply a shell completion suggestion by replacing the current word |