Skip to content

Commit

Permalink
fix(setup): update the current shell, not the preferred one (#4701)
Browse files Browse the repository at this point in the history
ref #4658
  • Loading branch information
zkochan committed May 9, 2022
1 parent 7c9362d commit 71c7ed9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/calm-ravens-rest.md
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-setup": patch
"pnpm": patch
---

`pnpm setup` should update the config of the current shell, not the preferred shell.
9 changes: 8 additions & 1 deletion packages/plugin-commands-setup/src/setup.ts
Expand Up @@ -50,7 +50,7 @@ export async function handler (
pnpmHomeDir: string
}
) {
const currentShell = typeof process.env.SHELL === 'string' ? path.basename(process.env.SHELL) : null
const currentShell = detectCurrentShell()
const execPath = getExecPath()
if (execPath.match(/\.[cm]?js$/) == null) {
copyCli(execPath, opts.pnpmHomeDir)
Expand All @@ -61,6 +61,13 @@ export async function handler (
Setup complete. Open a new terminal to start using pnpm.`
}

function detectCurrentShell () {
if (process.env.ZSH_VERSION) return 'zsh'
if (process.env.BASH_VERSION) return 'bash'
if (process.env.FISH_VERSION) return 'fish'
return typeof process.env.SHELL === 'string' ? path.basename(process.env.SHELL) : null
}

async function updateShell (currentShell: string | null, pnpmHomeDir: string): Promise<string> {
switch (currentShell) {
case 'bash': {
Expand Down

0 comments on commit 71c7ed9

Please sign in to comment.