Skip to content

Latest commit

 

History

History
313 lines (228 loc) · 5.15 KB

实用的命令行工具.md

File metadata and controls

313 lines (228 loc) · 5.15 KB

实用的命令行工具

fnm - Node.js 版本管理工具

跨平台的 node 版本管理工具(Fast Node Manager)

安装前,需要将已安装的 node 卸载

#  一键安装
curl -fsSL https://fnm.vercel.app/install | bash
#  brew 安装
brew install fnm
#  在 ~/.zshrc 中配置
eval "$(fnm env --use-on-cd)"

常用命令

# 查看 fnm 版本
fnm --version

# 安装最新的 LTS 版本
fnm install --lts

# 安装指定版本的 node
fnm install <版本号>

# 使用国内源安装
fnm install 16 --node-dist-mirror=https://npmmirror.com/mirrors/node

# 卸载指定版本的 node
fnm uninstall <版本号>

# 查看已安装的 node 版本
fnm ls

# 查看官方已发布的所有版本
fnm ls-remote

# 在当前 shell 使用指定的 node 版本
fnm use <版本号>

# 设置默认 node 版本
fnm default <版本号>

# 使用指定版本来执行某个全局命令
fnm exec --using=18 node -v

在特定目录自动切换版本

在应用目录写入文件并指定特定版本

echo '14' > .node-version
# OR
echo '14' > .nvmrc

检查 ~/.zshrc 文件是否配置了 --use-on-cd 参数

eval "$(fnm env --use-on-cd)"

nrm - npm 镜像管理工具

npm registry 管理工具,能够查看和切换当前使用的 registry

# 安装
npm install -g nrm

# 查看所有 registry
nrm ls

# 切换 registry
nrm use yarn

# 添加自定义 registry
 nrm add [别名] [registry 地址]

Github

ni - 包管理器工具

使用正确的软件包管理器运行项目,支持 npm、yarn、pnpm、bun

安装

npm i -g @antfu/ni
# OR
pnpm add -g @antfu/ni
# OR
yarn global add @antfu/ni

ni - install 安装依赖

# 安装依赖
ni
# npm install
# yarn install
# pnpm install
# bun install

# 安装指定包
ni vite
# npm i vite
# yarn add vite
# pnpm add vite
# bun add vite

# 安装指定包到开发依赖
ni @types/node -D
# npm i @types/node -D
# yarn add @types/node -D
# pnpm add -D @types/node
# bun add -d @types/node

# 使用锁定文件安装依赖
ni --frozen
# npm ci
# yarn install --frozen-lockfile (Yarn 1)
# yarn install --immutable (Yarn Berry)
# pnpm install --frozen-lockfile
# bun install --no-save

# 安装依赖到全局环境
ni -g eslint
# npm i -g eslint
# yarn global add eslint (Yarn 1)
# pnpm add -g eslint
# bun add -g eslint

全局安装时使用默认的包管理器

nr - run 运行脚本

nr dev --port=3000
# npm run dev -- --port=3000
# yarn run dev --port=3000
# pnpm run dev --port=3000
# bun run dev --port=3000

# 使用交互模式运行脚本
nr

# 重新运行上一条命令
nr -

nlx - 下载并执行

nlx vitest

# npx vitest
# yarn dlx vitest
# pnpm dlx vitest
# bunx vitest

nu - upgrade 升级依赖

nu
# (not available for bun)
# npm upgrade
# yarn upgrade (Yarn 1)
# yarn up (Yarn Berry)
# pnpm update

# 使用交互模式升级依赖
nu -i
# (not available for npm & bun)
# yarn upgrade-interactive (Yarn 1)
# yarn up -i (Yarn Berry)
# pnpm update -i

nun - uninstall 卸载依赖

nun webpack
# npm uninstall webpack
# yarn remove webpack
# pnpm remove webpack
# bun remove webpack

# 卸载全局依赖
nun -g silent
# npm uninstall -g silent
# yarn global remove silent
# pnpm remove -g silent
# bun remove -g silent

nci - clean install 清理安装

nci

# npm ci
# yarn install --frozen-lockfile
# pnpm install --frozen-lockfile
# bun install --no-save

na - agent alias 代理别名

na

# npm
# yarn
# pnpm
# bun

配置文件

~/.nirc

# 默认使用的包管理器(默认为 prompt)
defaultAgent=npm

# 全局安装时使用的包管理器
globalAgent=npm

@antfu/ni | Github

fig - 命令行提示工具

● 支持近 300 多种 CLI 工具的补全提示,如 cd git brew npm yarn ● 支持插件 ● 支持自定义补全规范

安装

brew install --cask fig

在 vscode 中使用,需修改 editor.accessibilitySupport 为 "off"

Github软件官网

bat - 显示文件内容

cat 命令的增强版,用于阅读文件

● 带行号 ● 语法高亮 ● Git 集成

# 查看主题列表
bat --list-themes

# 配置别名
alias cat="bat"

Homebrew 安装

brew install bat

bat | Github

fzf - 命令行模糊查找器

命令行模糊查找器

● 快捷键绑定(支持 bash、zsh 和 fish) ○ CTRL-T 在当前目录查找 ○ CTRL-R 查找历史命令 ● 预览 fzf --preview 'cat {}' 可结合 bat 使用

Homebrew 安装

brew install fzf

在 zsh 中使用时,快捷键绑定可能不生效,需要配置 plugins

# 在 ~/.zshrc 中配置
plugins=(其他插件 fzf)

# 使配置生效
source ~/.zshrc

修改默认配置

# 在 ~/.zshrc 中配置
export FZF_DEFAULT_OPTS="--layout=reverse --preview 'bat -n --color=always {}'"

fzf | Github