vscode 终端 进入node_如何在打开新的集成终端VSCode Mac时运行install node.js?

我不认为VSCode在第一次打开shell时应该在shell上运行任何东西,因为这正是

.bashrc

,

.zshrc

以及其他类似的文件。

巴什尔

find-up () {

path=$(pwd)

while [[ "$path" != "" && ! -e "$path/$1" ]]; do

path=${path%/*}

done

echo "$path"

}

cdnvm(){

cd "$@";

nvm_path=$(find-up .nvmrc | tr -d '[:space:]')

# If there are no .nvmrc file, use the default nvm version

if [[ ! $nvm_path = *[^[:space:]]* ]]; then

declare default_version;

default_version=$(nvm version default);

# If there is no default version, set it to `node`

# This will use the latest version on your machine

if [[ $default_version == "N/A" ]]; then

nvm alias default node;

default_version=$(nvm version default);

fi

# If the current version is not the default version, set it to use the default version

if [[ $(nvm current) != "$default_version" ]]; then

nvm use default;

fi

elif [[ -s $nvm_path/.nvmrc && -r $nvm_path/.nvmrc ]]; then

declare nvm_version

nvm_version=$(

declare locally_resolved_nvm_version

# `nvm ls` will check all locally-available versions

# If there are multiple matching versions, take the latest one

# Remove the `->` and `*` characters and spaces

# `locally_resolved_nvm_version` will be `N/A` if no local versions are found

locally_resolved_nvm_version=$(nvm ls --no-colors "$nvm_version" | tail -1 | tr -d '\->*' | tr -d '[:space:]')

# If it is not already installed, install it

# `nvm install` will implicitly use the newly-installed version

if [[ "$locally_resolved_nvm_version" == "N/A" ]]; then

nvm install "$nvm_version";

elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then

nvm use "$nvm_version";

fi

fi

}

alias cd='cdnvm'

cd .

我真的做了一个

PR

nvm-sh/nvm

包含此片段的存储库,现在它是

documentation

. 我会用那里的版本。

zsh

. 如果使用另一个shell,则可能需要复制相同的逻辑。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值