Skip to content

Commit e344956

Browse files
committed
fix(cli): normalize paths for Windows compatibility in completion and tildify
- completion: Convert backslashes to forward slashes for Bash scripts - tildify: Accept both / and \ as path separators on Windows - Fixes path mismatches in Git Bash, WSL, and other Windows environments
1 parent 04ba0ca commit e344956

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/cli/src/utils/cli/completion.mts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ export function getCompletionSourcingCommand(): CResult<string> {
1919
return {
2020
ok: false,
2121
message: 'Tab Completion script not found',
22-
cause: `Expected to find completion script at \`${completionScriptPath}\` but it was not there`,
22+
cause: `Expected to find completion script at \`${completionScriptPath.replace(/\\/g, '/')}\` but it was not there`,
2323
}
2424
}
2525

26-
return { ok: true, data: `source ${completionScriptPath}` }
26+
// Bash scripts always use forward slashes, even on Windows.
27+
return { ok: true, data: `source ${completionScriptPath.replace(/\\/g, '/')}` }
2728
}
2829

2930
export function getBashrcDetails(targetCommandName: string): CResult<{
@@ -57,10 +58,13 @@ export function getBashrcDetails(targetCommandName: string): CResult<{
5758
'socket-completion.bash',
5859
)
5960

61+
// Bash scripts always use forward slashes, even on Windows.
62+
const bashCompletionPath = completionScriptPath.replace(/\\/g, '/')
63+
6064
const bashrcContent = `# Socket CLI completion for "${targetCommandName}"
61-
if [ -f "${completionScriptPath}" ]; then
65+
if [ -f "${bashCompletionPath}" ]; then
6266
# Load the tab completion script
63-
source "${completionScriptPath}"
67+
source "${bashCompletionPath}"
6468
# Tell bash to use this function for tab completion of this function
6569
${completionCommand}
6670
fi

packages/cli/src/utils/fs/home-path.mts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Usage:
99
* - Shortens absolute paths for display
10-
* - Converts /Users/name/... to ~/...
10+
* - Converts absolute home paths to ~/...
1111
* - Common Unix convention for home directory
1212
*/
1313

@@ -18,8 +18,11 @@ import { escapeRegExp } from '@socketsecurity/lib/regexps'
1818
import { homePath } from '../../constants/paths.mts'
1919

2020
export function tildify(cwd: string) {
21+
// On Windows, accept both forward and back slashes as separators
22+
// since paths can be mixed (Git Bash, WSL, etc.).
23+
const sepPattern = path.sep === '\\' ? '[\\\\/]' : '/'
2124
return cwd.replace(
22-
new RegExp(`^${escapeRegExp(homePath)}(?:${path.sep}|$)`, 'i'),
25+
new RegExp(`^${escapeRegExp(homePath)}(?:${sepPattern}|$)`, 'i'),
2326
'~/',
2427
)
2528
}

0 commit comments

Comments
 (0)