Mac终端终极优化

Mac终端终极优化

马草原 683 2022-03-06

Mac终端终极优化

安装Homebrew

官网:https://brew.sh/

Homebrew是 Mac 必备工具,它是 Mac 的安装包管理工具。新电脑默认没有安装,需要手动安装。
当你在安装软件时,先看一下能不能用Homebrew安装,能的话就不要考虑其他安装方式了。非常便捷省心!

安装Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

安装iTerm2

官网:https://iterm2.com/
这个无需解释了,终端神器,每个程序员的必备工具。

安装iTerm2:

brew cask install iterm2

安装Alacritty(iTerm2备选)

官网:https://alacritty.org

号称比 iTerm2 快的终端模拟器,但使用的用户没有 iTerm2 多。Alacritty 和 iTerm2 两者选其一就行了。

安装Alacritty:

brew cask install alacritty

其实Mac 原生 Terminal 终端也很好用🤣

安装oh-my-zsh

官网:https://ohmyz.sh

现在的 Mac 电脑默认 Shell 解释器是 zsh。当你电脑只有 zsh,而没有 oh-my-zsh 时,通常认为是不完整的。

安装oh-my-zsh:

/bin/bash -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"

💡Tips:在研究如何给 oh-my-zsh 写一个插件时,发现以下这些插件 oh-my-zsh 已经自带了(在 ~/.oh-my-zsh/plugins/),只是没有启用而已。所以不需要再下载了。只需要在 ~/.zshrc 中的 plugins 数组内添加要启用的插件名称即可。

但你只安装 oh-my-zsh 了,而没有安装这些极为好用的插件,那使用起来还会差点意思的。

官方的插件:https://github.com/zsh-users/

这里推荐使用频率最高的三个插件:

1. 路径自动补全插件zsh-autosuggestions :

GIthub:https://github.com/zsh-users/zsh-autosuggestions

有下面两种安装方式,推荐使用第 2 种安装。

1.官方推荐安装:

git clone https://github.com/zsh-users/zsh-autosuggestions.git ~/.zsh/zsh-autosuggestions
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

2.以 ohmyzsh 插件的方式安装

cd ~/.oh-my-zsh/custom/plugins
git clone https://github.com/zsh-users/zsh-autosuggestions.git

打开~/.zshrc ,在plugins中增加zsh-autosuggestions

plugins=(git zsh-autosuggestions)

2. shell 语法高亮插件zsh-syntax-highlighting

cd ~/.oh-my-zsh/custom/plugins
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git

打开~/.zshrc,在plugins中增加zsh-syntax-highlighting

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)

3. 终端快速直达目录插件 Z

比较有名的快速直达目录的插件有 autojump、z、z.lua,都差不多,这里推荐 z。

cd ~/.oh-my-zsh/custom/plugins
git clone git@github.com:rupa/z.git

打开~/.zshrc,在plugins中增加 z

plugins=(git zsh-autosuggestions zsh-syntax-highlighting z)

以上插件完成安装后,重启终端或执行一下命令才能生效:

source ~/.zshrc

安装Go2Shell

官网:https://zipzapmac.com/Go2Shell

当你在 Finder 浏览文件时,想直接打开终端并跳转到这个路径下,常规的做法是先打开终端,然后把文件(夹)拖拽到终端,再按下回车,才能进入到这个目录。而 Go2Shell 能把上面的三步缩短至一个点击。

建议在App Store中直接安装


其他小工具推荐

ccat - 带颜色的 cat

brew install ccat

可以设置别名,替代 cat。

fzf - 交互式的模糊搜索

brew install fzf

jq - 格式化带样式显示 JSON

brew install jq

cloc - 源代码行数统计

brew install cloc

tree - 显示目录树

brew install tree

terminal