Mac 小记 — iTerm2、Zsh、Homebrew
前言
写完 “Ubuntu 自动化配置” 这篇文章后,每次连服务器心情指数都上升好几个百分点,于是想着应该将 macOs 的开发环境也梳理梳理,应该会对开发效率有所增益。

1. iTerm2 配置
虽然Mac默认的终端已经非常强大,但从功能的丰富程度和开发效率上来看,对于我来说iterm2无疑是更优选择。安装完毕后第一步就是开启 Hotkey-Window(Preferences→Keys→Create a Dedicated Hotkey Window),我习惯给其录制的快捷键是:Option+Space,从此终端召之即来挥之即去,这能给予我一切尽在掌握之中的满足感。
1.1 偏好调整
以下三点我认为还需加以调整才能愉快玩耍:
Ⅰ. 配色问题
iterm2 默认的配色对蓝色不是很友好,特别是半透明的情况下很难看清楚,我一般将其颜色值改为:268bd2,前景色直接设为白色,更改前后对比:

Ⅱ. 快速跳过单词问题
⌥ + ↔ 本是向前或者向后跳过一个单词,但是却变成了这种字符 [D[C,修复方法:在每个窗口设置的 keys 中更改相应的快捷键,如下图:

Ⅲ. 新建标签页问题
⌘ + T 为新建标签页,但是在 Hotkey-Window 中我需要新建同类别的标签页而不是默认,因此需要明确指定其快捷键:

1.2 常用功能简述
iterm2 功能丰富,然而很多是锦上添花,与其去记复杂的快捷键还不如多操作几步,我认为有必要去记的也就这么几个:
⌘+N、⌘+T、⌘+↔、⌘+F、⌘+W这几个快捷键就不解释了。⌘+D垂直分屏、⌘+⇧+D水平分屏、⌘+⌥+↑↓↔切换分屏。⌘+↩全屏、⌘ + R清屏。⌃+A/E行首/尾、⌃+R查询历史命令。⌥+↔左右跳过单词。
记住这些就差不多了,脑容量有限,应能省则省。
2. zsh 配置
使用 zsh 已经很长时间了,上篇文章 整理了一些 linux 中 bash 的配置,本想扩展一下使其满足 macOs 中更丰富的应用场景。但经历一番从开始到放弃之后,我决定重新整理一下 zsh 的配置。
2.1 oh-my-zsh
查看当前使用的 shell:echo $SHELL,切换 zsh:chsh -s /bin/zsh。托开源社区的福,平凡和华丽之间只有一行代码的距离:

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
2.2 别名
zsh 的配置文件是 .zshrc,从名字上就能看的出来,默认已经设置了好多别名,都还蛮有用的:
-='cd -'
...=../..
....=../../..
.....=../../../..
......=../../../../..
1='cd -'
2='cd -2'
3='cd -3'
4='cd -4'
5='cd -5'
6='cd -6'
7='cd -7'
8='cd -8'
9='cd -9'
_=sudo
afind='ack -il'
d='dirs -v | head -10'
g=git
ga='git add'
gaa='git add --all'
gap='git apply'
gapa='git add --patch'
gau='git add --update'
gb='git branch'
gba='git branch -a'
gbd='git branch -d'
gbda='git branch --no-color --merged | command grep -vE "^(\*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d'
gbl='git blame -b -w'
gbnm='git branch --no-merged'
gbr='git branch --remote'
gbs='git bisect'
gbsb='git bisect bad'
gbsg='git bisect good'
gbsr='git bisect reset'
gbss='git bisect start'
gc='git commit -v'
'gc!'='git commit -v --amend'
gca='git commit -v -a'
'gca!'='git commit -v -a --amend'
gcam='git commit -a -m'
'gcan!'='git commit -v -a --no-edit --amend'
'gcans!'='git commit -v -a -s --no-edit --amend'
gcb='git checkout -b'
gcd='git checkout develop'
gcf='git config --list'
gcl='git clone --recursive'
gclean='git clean -fd'
gcm='git checkout master'
gcmsg='git commit -m'
'gcn!'='git commit -v --no-edit --amend'
gco='git checkout'
gcount='git shortlog -sn'
gcp='git cherry-pick'
gcpa='git cherry-pick --abort'
gcpc='git cherry-pick --continue'
gcs='git commit -S'
gcsm='git commit -s -m'
gd='git diff'
gdca='git diff --cached'
gdct='git describe --tags `git rev-list --tags --max-count=1`'
gdcw='git diff --cached --word-diff'
gdt='git diff-tree --no-commit-id --name-only -r'
gdw='git diff --word-diff'
gf='git fetch'
gfa='git fetch --all --prune'
gfo='git fetch origin'
gg='git gui citool'
gga='git gui citool --amend'
ggpull='git pull origin $(git_current_branch)'
ggpur=ggu
ggpush='git push origin $(git_current_branch)'
ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
ghh='git help'
gignore='git update-index --assume-unchanged'
gignored='git ls-files -v | grep "^[[:lower:]]"'
git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
gk='\gitk --all --branches'
gke='\gitk --all $(git log -g --pretty=%h)'
gl='git pull'
glg='git log --stat'
glgg='git log --graph'
glgga='git log --graph --decorate --all'
glgm='git log --graph --max-count=10'
glgp='git log --stat -p'
glo='git log --oneline --decorate'
globurl='noglob urlglobber '
glog='git log --oneline --decorate --graph'
gloga='git log --oneline --decorate --graph --all'
glol='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit'
glola='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --all'
glp=_git_log_prettily
glum='git pull upstream master'
gm='git merge'
gma='git merge --abort'
gmom='git merge origin/master'
gmt='git mergetool --no-prompt'
gmtvim='git mergetool --no-prompt --tool=vimdiff'
gmum='git merge upstream/master'
gp='git push'
gpd='git push --dry-run'
gpoat='git push origin --all && git push origin --tags'
gpristine='git reset --hard && git clean -dfx'
gpsup='git push --set-upstream origin $(git_current_branch)'
gpu='git push upstream'
gpv='git push -v'
gr='git remote'
gra='git remote add'
grb='git rebase'
grba='git rebase --abort'
grbc='git rebase --continue'
grbi='git rebase -i'
grbm='git rebase master'
grbs='git rebase --skip'
grep='grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}'
grh='git reset HEAD'
grhh='git reset HEAD --hard'
grmv='git remote rename'
grrm='git remote remove'
grset='git remote set-url'
grt='cd $(git rev-parse --show-toplevel || echo ".")'
gru='git reset --'
grup='git remote update'
grv='git remote -v'
gsb='git status -sb'
gsd='git svn dcommit'
gsi='git submodule init'
gsps='git show --pretty=short --show-signature'
gsr='git svn rebase'
gss='git status -s'
gst='git status'
gsta='git stash save'
gstaa='git stash apply'
gstc='git stash clear'
gstd='git stash drop'
gstl='git stash list'
gstp='git stash pop'
gsts='git stash show --text'
gsu='git submodule update'
gts='git tag -s'
gtv='git tag | sort -V'
gunignore='git update-index --no-assume-unchanged'
gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
gup='git pull --rebase'
gupv='git pull --rebase -v'
gwch='git whatchanged -p --abbrev-commit --pretty=medium'
gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify -m "--wip-- [skip ci]"'
history='fc -l 1'
l='ls -lah'
la='ls -lAh'
ll='ls -lh'
ls='ls -G'
lsa='ls -lah'
md='mkdir -p'
please=sudo
po=popd
pu=pushd
rd=rmdir
run-help=man
which-command=whence
我经常记不住打包和压缩的命令,因此增加以下别名:
alias t="tar -cvf"
alias gz="tar -czvf"
alias bz2="tar -cjvf"
2.3 插件
大头来了,列举一些常用的:
2.3.1 git
git 是唯一默认启用的插件,通用配置在上篇文章中已经详细说明。在 macOs 中建议在用户目录中增加全局的忽略文件 .gitignoreglobal 用于忽略 macOS 文件夹属性文件 .DS_Store,同时执行 git config --global core.excludesfile ~/.gitignoreglobal。多账号自动切换用户信息的代码建议添加到 ~/.oh-my-zsh/lib/git.zsh 中的 git_prompt_info 函数:
function git_prompt_info() {
local ref
if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
# switch user
if [ -z `git config user.name` ] && [ -z `git config user.email` ]; then
local git_remote=`git remote -v`
if [[ $git_remote =~ "github" ]]; then
`git config user.name "github" && git config user.email "github@youclk.com"`
elif [[ $git_remote =~ "gitee" ]]; then
`git config user.name "gitee" && git config user.email "gitee@youclk.com"`
fi
fi
fi
}
2.3.2 autojump
当你的工作目录比较复杂的时候,这个插件的价值就体现出来了。它会读取历史记录,之后只要j dir就可以愉快地跳转。安装也及其简单:brew install autojump,然后编辑 .zshrc 文件,在插件选项中添加 autojump 即可。
2.3.3 zsh-autosuggestions
我对它可以说是一见钟情,其实这个插件对于生产效率的提升并不明显,但耐不住看着舒服呀:

安装:git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions,后续步骤同上。
2.3.4 extract
正如我记不住打包和压缩的命令,解压等命令也是如此,因为实在是不大常用。之前也是靠别名,直到发现这个插件统一了解压命令:x。

3. Homebrew 配置
它毫无疑问是 macOS 最流行的包管理器,安装就一行代码:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)",使用也没啥好说的:
brew install package
brew uninstall package
# 下载第三方应用
brew cask install qq
brew cask uninstall qq
有必要记录的是更换镜像源,我选择的是中科大镜像:
# 替换 brew.git:
# https://github.com/Homebrew/brew
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 替换 homebrew-core.git:
# https://github.com/Homebrew/homebrew-core
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 设置 Homebrew Bottles环境变量
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
结语
以上三个软件是我认为拿到 mac 起就必须安装配置的,无论这台 mac 将被用于什么业务,这是愉快玩耍 macOs 的基础。后续若有空我会将我个人的 macOs 开发环境做一个归纳,敬请期待。
我的公众号《有刻》,我们共同成长!

Mac 小记 — iTerm2、Zsh、Homebrew的更多相关文章
- 给你的Mac 整个好用的命令行iTerm2 + zsh + oh-my-zsh + powerlevel10k
给你的Mac 整个好用的命令行iTerm2 + zsh + oh-my-zsh + powerlevel10k 介绍 iTerm2 是一个MacOS 下的终端模拟器,和其他的终端本质上没啥大不同.但相 ...
- 2019.1.9 Mac安装Iterm2 终端(oh my zsh的安装与配置)
Mac安装Iterm2 终端(oh my zsh的安装与配置) 安装 curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tool ...
- Mac OS 终端强化美化:iterm2 + zsh + oh~my~zsh 设置教程
为了获得更好的排版效果,文章改用markdown撰写,故重发一次. 前言 mac自带的terminal终端没有文件名高亮等功能,而且界面不是很好看,故今晚学舍友折腾了终端,可以让自己使用起来更加方便, ...
- Mac终端美化(iterm2+zsh+oh-my-zsh+powerlevel10k)
iterm2+zsh+oh-my-zsh+powerlevel10k 一.下载iterm2 方式一:官网下载 https://iterm2.com/ 方式二:百度云下载 链接: https://pan ...
- 为MAC配置终端环境iTerm2+Zsh+oh-my-zsh
首先展示下我的终端吧. 这就是我们为什么要配置iTerm2+Zsh+oh-my-zsh环境的原因: 我们使用zsh解释器,当然等你使用 zsh时就会知道zsh与bash对比的强大之处了. 至于我们的g ...
- iterm2 + zsh + oh-my-zsh +autojump
iterm2 + zsh + oh-my-zsh +autojump 升级你的命令行工具,这个我折腾了好久,才明白了各个之间的关系. 1.先下载一个item2 首先你需要下一个iterm2,不要 ...
- Mac下iTerm2配置lrzsz功能
Mac下iTerm2配置lrzsz功能 rz,sz是Linux/Unix同Windows进行ZModem文件传输的命令行工具. 优点就是不用再开一个sftp工具登录上去上传下载文件. 近期在mac上通 ...
- (转)Building MariaDB on Mac OS X using Homebrew
https://kb.askmonty.org/en/building-mariadb-on-mac-os-x-using-homebrew/ Work has been done to provid ...
- mac 使用iTerm2快捷登录远程服务器
mac 使用iTerm2快捷登录远程服务器 正常使用ssh登录服务器: ssh -p port user@host user@host's password: 输入端口,用户名,服务器ip地址后,还需 ...
随机推荐
- [katalon] 页面切换
UI自动化测试过程中会涉及到需要切换多个页面, 如点击一个按钮之后跳转到新的页面, 后者A站点提交信息后,B站点审核. Katalon虽然不支持控制多个浏览器,但是支持处理tab切换. 核心方法是使用 ...
- MySQL查询日志总结
MySQL查询日志介绍 MySQL的查询日志记录了所有MySQL数据库请求的信息.无论这些请求是否得到了正确的执行.默认文件名为hostname.log.默认情况下MySQL查询日志是关闭的.生产环境 ...
- Sql Full-Text Filter
SQL Server 全文索引介绍(转载) 概述 全文引擎使用全文索引中的信息来编译可快速搜索表中的特定词或词组的全文查询.全文索引将有关重要的词及其位置的信息存储在数据库表的一列或多列中.全文索引是 ...
- SQL Server 锁机制
锁兼容性图: 一.锁的粒度: 比较需要注意的是RID/KEY.HoBT/PAGE这两对儿的区别,RID和HoBT是针对堆表的,即没有聚集索引的表. 二.锁的模式: 1.关于其中的S.U.X锁: 共享锁 ...
- window scoop 修改默认安装路径
1.运行powershell [environment]::setEnvironmentVariable('SCOOP_GLOBAL','F:\GlobalScoopApps','Machine') ...
- JavaScript实现元素拖动性能优化
前言:前几天没事干写了个小网站,打算用原生的javascript实现元素的拖动,但是事情并没有想象的那么顺利,首先是实现了拖动的元素卡的不能再卡,简直不能够,上图~~ 看见没?这就是效果,简直让人欲哭 ...
- Pyqt5+python+ErIC6+QT designer
Eric6安装及配置 https://blog.csdn.net/weixin_41656968/article/details/80253012 Python3.6+PyQt5+Eric6.0环境配 ...
- 数据合并处理concat
var data = [ {name: '海门', value: 9}, {name: '鄂尔多斯', value: 12}, {name: '招远', value: 12}, {name: '舟山' ...
- pip自动生成和安装requirements.txt
生成requirements.txt文件 pip freeze > requirements.txt 安装requirements.txt依赖 pip install -r requiremen ...
- centos7下安装docker(18.1docker日志---logging driver)
将容器的日志发送到STDOUT和STDERR是docker的默认日志行为.实际上,docker提供了多种日志机制帮助用户从容器中提取日志,这些机制被称为logging driver docker的默认 ...