apptools-lab / AppToolkit

🐘 The Front-end Env Toolkit(前端环境管理工具)
571 stars 73 forks source link

Feat: use default shell to excute sh file #57

Closed luhc228 closed 3 years ago

luhc228 commented 3 years ago

背景

目前,安装 nvm 时会调用 shell 脚本 sh install.sh (install.sh 是来自于 https://github.com/nvm-sh/nvm)。假如现在同时存在 .bash_profile 和 .zshrc 时并且默认的 shell 是 /bin/zsh 时,会把 nvm 的配置写到 .bash_profile 中,但是期望的是 .zshrc。

解决

需要先获取当前的 shell,然后再去调用执行 install.sh

function getShellName(): string {
  const shellPath = process.env.SHELL;
  const splitPaths = shellPath.split('/');
  return splitPaths[splitPaths.length - 1];
}

getShellName();        // zsh or sh or bash