- 前言
- 安装
- zsh插件安装
- zsh主题美化
- 小技巧
- 配置.zshrc
Author: 颖奇L’Amore
Blog: www.gem-love.com
MacOS高效使用文章合集:here
前言▸
苹果自带的Terminal虽然也不是不能用,但是多少还是不够好用
安装▸
iTerm2从官网下载即可 https://iterm2.com/
zsh的安装比较简单,安装后还需要oh-my-zsh,相当于是zsh的扩展
代码语言:javascript复制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插件安装▸
两个好用的插件(代码补全和高亮)
代码语言:javascript复制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,安装:
代码语言:javascript复制git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
可能会遇到字体问题,安装字体:
代码语言:javascript复制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 Sans Mono Nerd Font Complete.otf
# 之后进入~/.local/share/fonts安装
修改.zshrc
:
ZSH_THEME="powerlevel10k/powerlevel10k"
然后会自动进入p10k的配置,也可以p10k configure
命令手工开始配置,我的效果如下:
小技巧▸
ls得到文件后 摁住cmd点击可以在Finder中打开,摁住cmd拖动即可快速cd过去
配置.zshrc▸
可以利用alias
进行很多操作的简化,例如我的:
<span class="hljs-built_in">alias</span> pr=<span class="hljs-string">'export all_proxy=socks5://localhost:7890'</span>
<span class="hljs-built_in">alias</span> nopr=<span class="hljs-string">'unset all_proxy'</span>
<span class="hljs-built_in">alias</span> ip=<span class="hljs-string">'curl http://23.80.5.90/ip.php'</span>
<span class="hljs-built_in">alias</span> py=<span class="hljs-string">'/usr/bin/python3'</span>
<span class="hljs-built_in">alias</span> des=<span class="hljs-string">'cd /Users/amortang/Desktop'</span>
<span class="hljs-built_in">alias</span> hs=<span class="hljs-string">'cd $blog && hexo clear & hexo g & hexo s'</span>
<span class="hljs-built_in">alias</span> hd=<span class="hljs-string">'cd $blog && hexo clear & hexo g & hexo d'</span>
<span class="hljs-built_in">alias</span> ca=<span class="hljs-string">'open -a Calculator.app'</span>
想要python3执行什么脚本只要py一下即可,非常方便。
还可以将一些常用路径定义为变量,方便直接切换过去, 例如:
代码语言:javascript复制www=/Applications/MxSrvs/www