npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

auto-run-terminal

v1.0.2

Published

Mac终端/VS Code终端打开时自动执行指定脚本,安装即生效

Readme

auto-run-terminal

Mac终端/VS Code终端打开时自动执行指定脚本,安装即生效

这是一个为macOS用户设计的终端自动执行脚本工具,可以在打开终端或VS Code终端时自动检测并切换到项目指定的Node.js版本。

✨ 功能特性

  • 自动Node.js版本切换:根据项目package.json中的nodeVersion字段自动切换Node.js版本
  • 多环境支持:支持系统终端、iTerm2、VS Code终端等多种终端环境
  • 零配置使用:安装后自动配置,无需手动设置
  • 智能检测:只在包含package.json的目录中执行,避免不必要的操作
  • 优雅降级:未安装nvm时提供友好提示,不影响正常使用

🚀 快速开始

安装

npm install -g auto-run-terminal

或者作为项目依赖安装:

npm install auto-run-terminal

使用

  1. 在项目根目录的package.json中添加nodeVersion字段:
{
  "name": "your-project",
  "nodeVersion": "18",
  // 其他配置...
}
  1. 安装完成后,每次打开终端或VS Code终端时,脚本会自动执行

🔧 工作原理

该工具通过以下步骤实现自动执行:

  1. 安装阶段npm install时会触发postinstall脚本
  2. 配置阶段:自动修改用户~/.zshrc文件,添加自动执行配置
  3. 执行阶段:每次打开终端时,自动检测当前目录是否有package.json
  4. 版本切换:读取nodeVersion字段并使用nvm切换到指定版本

📁 项目结构

auto-run-terminal/
├── bin/
│   └── auto-config.js          # 安装配置脚本
├── scripts/
│   ├── auto-switch-node.sh     # Bash版本自动切换脚本
│   ├── my-auto-script.js       # Node.js版本自动切换脚本
│   └── my-auto-script.sh       # 备用Bash版本自动切换脚本
├── package.json                # 项目配置
└── README.md                   # 项目文档

📝 配置说明

package.json配置

在项目的package.json中添加nodeVersion字段:

{
  "nodeVersion": "18"
}

支持多种格式:

  • "18" - 使用Node.js 18.x版本
  • "v16.20.0" - 使用指定版本
  • "lts" - 使用LTS版本

环境要求

  • macOS系统
  • zsh shell(macOS默认)
  • nvm(Node Version Manager)已安装

🔍 故障排除

nvm未安装

如果提示"未检测到 nvm",请按以下步骤安装:

# 使用curl安装
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# 或使用wget安装
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# 安装后重启终端或执行
source ~/.zshrc

配置未生效

如果配置未生效,请尝试:

# 手动source配置文件
source ~/.zshrc

# 或重启终端应用程序

VS Code终端不生效

确保VS Code使用的是系统默认的zsh shell:

  1. 打开VS Code设置
  2. 搜索terminal.integrated.defaultProfile.osx
  3. 设置为zsh

🛠️ 开发指南

项目安装

git clone <repository-url>
cd auto-run-terminal
npm install

本地测试

# 测试配置脚本
node bin/auto-config.js

# 测试自动切换脚本
./scripts/auto-switch-node.sh

构建发布

# 发布到npm
npm publish

🗑️ 卸载

推荐卸载方法

为了确保完全卸载,建议使用以下命令:

# 全局卸载
npm uninstall -g auto-run-terminal

手动卸载

如果上述方法不生效,可以手动执行卸载脚本:

卸载脚本功能

卸载脚本会:

  1. ~/.zshrc中移除auto-run-terminal相关的所有配置
  2. 清理多余的空行,保持文件整洁
  3. 提示重启终端或执行source ~/.zshrc使更改生效

验证卸载

卸载完成后,可以检查~/.zshrc文件中是否还存在以下内容:

  • # AUTO-RUN-TERMINAL-CONFIG (START DO NOT DELETE)
  • # AUTO-RUN-TERMINAL-CONFIG (END DO NOT DELETE)
  • source命令指向auto-run-terminal的脚本

如果这些内容已不存在,说明卸载成功。