Skip to content

Commit d239db3

Browse files
committed
fix(vscode): list only exported variables and stop PowerShell truncating
fish's bare `set` also lists shell-local variables, so it is now `set -x`, which matches what the other families print. PowerShell's default table view truncates values at the console width, so each variable is now formatted explicitly as `NAME=value`. Adds the pwsh-off-Windows case for printEnvironmentCommand, and the SPDX headers both new files were missing. Signed-off-by: Adegbite Ayoade <tripleaceme@gmail.com>
1 parent 7264ccf commit d239db3

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎vscode/extension/src/utilities/shellCommand.test.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
13
import { describe, it, expect } from 'vitest'
24
import { detectShellFamily, printEnvironmentCommand } from './shellCommand'
35

6+
const POWERSHELL_COMMAND =
7+
"Get-ChildItem Env: | Sort-Object Name | ForEach-Object { '{0}={1}' -f $_.Name, $_.Value }"
8+
49
describe('detectShellFamily', () => {
510
it('should detect fish', () => {
611
expect(detectShellFamily('/usr/bin/fish', false)).toBe('fish')
@@ -62,8 +67,8 @@ describe('detectShellFamily', () => {
6267
})
6368

6469
describe('printEnvironmentCommand', () => {
65-
it('should use set in fish', () => {
66-
expect(printEnvironmentCommand('/usr/bin/fish', false)).toBe('set')
70+
it('should use the exported-only set in fish', () => {
71+
expect(printEnvironmentCommand('/usr/bin/fish', false)).toBe('set -x')
6772
})
6873

6974
it('should use env | sort in POSIX shells', () => {
@@ -84,7 +89,14 @@ describe('printEnvironmentCommand', () => {
8489
'C:\\Program Files\\PowerShell\\7\\pwsh.exe',
8590
true,
8691
),
87-
).toBe('Get-ChildItem Env: | Sort-Object Name')
92+
).toBe(POWERSHELL_COMMAND)
93+
})
94+
95+
it('should use the PowerShell command for pwsh off Windows', () => {
96+
expect(printEnvironmentCommand('/usr/local/bin/pwsh', false)).toBe(
97+
POWERSHELL_COMMAND,
98+
)
99+
expect(printEnvironmentCommand('pwsh', false)).toBe(POWERSHELL_COMMAND)
88100
})
89101

90102
it('should keep the previous behaviour when the shell is unknown', () => {

‎vscode/extension/src/utilities/shellCommand.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
13
/**
24
* The shell families we know how to print environment variables in.
35
*/
@@ -6,10 +8,16 @@ export type ShellFamily = 'fish' | 'powershell' | 'cmd' | 'posix'
68
/**
79
* Commands that list the environment variables of the current shell, one per
810
* shell family.
11+
*
12+
* `set -x` is fish's exported-only listing, which matches what the other
13+
* families print; a bare `set` would also include shell-local variables.
14+
* PowerShell formats each variable itself because the default table view
15+
* truncates values at the console width.
916
*/
1017
const PRINT_ENVIRONMENT_COMMANDS: Record<ShellFamily, string> = {
11-
fish: 'set',
12-
powershell: 'Get-ChildItem Env: | Sort-Object Name',
18+
fish: 'set -x',
19+
powershell:
20+
"Get-ChildItem Env: | Sort-Object Name | ForEach-Object { '{0}={1}' -f $_.Name, $_.Value }",
1321
cmd: 'set',
1422
posix: 'env | sort',
1523
}

0 commit comments

Comments
 (0)