( options?: ShellConfigOptions, )
| 142 | * @param options Optional overrides for testing (env, homedir) |
| 143 | */ |
| 144 | export async function findValidClaudeAlias( |
| 145 | options?: ShellConfigOptions, |
| 146 | ): Promise<string | null> { |
| 147 | const aliasTarget = await findClaudeAlias(options) |
| 148 | if (!aliasTarget) return null |
| 149 | |
| 150 | const home = options?.homedir ?? osHomedir() |
| 151 | |
| 152 | // Expand ~ to home directory |
| 153 | const expandedPath = aliasTarget.startsWith('~') |
| 154 | ? aliasTarget.replace('~', home) |
| 155 | : aliasTarget |
| 156 | |
| 157 | // Check if the target exists and is executable |
| 158 | try { |
| 159 | const stats = await stat(expandedPath) |
| 160 | // Check if it's a file (could be executable or symlink) |
| 161 | if (stats.isFile() || stats.isSymbolicLink()) { |
| 162 | return aliasTarget |
| 163 | } |
| 164 | } catch { |
| 165 | // Target doesn't exist or can't be accessed |
| 166 | } |
| 167 | |
| 168 | return null |
| 169 | } |
no test coverage detected