使用iTerm2+zsh替代苹果自带Terminal
2022-4-19 19:20:22 Author: www.gem-love.com(查看原文) 阅读量:7 收藏

Author: 颖奇L’Amore

Blog: www.gem-love.com


MacOS高效使用文章合集:here

前言

苹果自带的Terminal虽然也不是不能用,但是多少还是不够好用

安装

iTerm2从官网下载即可 https://iterm2.com/

zsh的安装比较简单,安装后还需要oh-my-zsh,相当于是zsh的扩展

brew install zsh zsh-completions
sudo chsh -s /bin/zsh
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

zsh插件安装

两个好用的插件(代码补全和高亮)

brew install zsh-autosuggestions
brew install zsh-syntax-highlighting

也可以用git

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

装好后在.zshrc文件中开启

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

zsh主题美化

我使用的是powerlevel10k,安装:

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

可能会遇到字体问题,安装字体:

mkdir -p ~/.local/share/fonts
cd ~/.local/share/fonts && curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete.otf
# 之后进入~/.local/share/fonts安装

修改.zshrc

ZSH_THEME="powerlevel10k/powerlevel10k"

然后会自动进入p10k的配置,也可以p10k configure命令手工开始配置,我的效果如下:

小技巧

ls得到文件后 摁住cmd点击可以在Finder中打开,摁住cmd拖动即可快速cd过去
232417_QQ20220423-232345-HD

配置.zshrc

可以利用alias进行很多操作的简化,例如我的:

alias pr='export all_proxy=socks5://localhost:7890'
alias nopr='unset all_proxy'
alias ip='curl http://23.80.5.90/ip.php'
alias py='/usr/bin/python3'
alias des='cd /Users/amortang/Desktop'
alias hs='cd $blog && hexo clear & hexo g & hexo s'
alias hd='cd $blog && hexo clear & hexo g & hexo d'
alias ca='open -a Calculator.app'

想要python3执行什么脚本只要py一下即可,非常方便。

还可以将一些常用路径定义为变量,方便直接切换过去, 例如:

www=/Applications/MxSrvs/www

Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.


文章来源: https://www.gem-love.com/2022/04/19/%E4%BD%BF%E7%94%A8iTerm2-zsh%E6%9B%BF%E4%BB%A3%E8%8B%B9%E6%9E%9C%E8%87%AA%E5%B8%A6Terminal/
如有侵权请联系:admin#unsafe.sh