前言

写完 “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的更多相关文章

  1. 给你的Mac 整个好用的命令行iTerm2 + zsh + oh-my-zsh + powerlevel10k

    给你的Mac 整个好用的命令行iTerm2 + zsh + oh-my-zsh + powerlevel10k 介绍 iTerm2 是一个MacOS 下的终端模拟器,和其他的终端本质上没啥大不同.但相 ...

  2. 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 ...

  3. Mac OS 终端强化美化:iterm2 + zsh + oh~my~zsh 设置教程

    为了获得更好的排版效果,文章改用markdown撰写,故重发一次. 前言 mac自带的terminal终端没有文件名高亮等功能,而且界面不是很好看,故今晚学舍友折腾了终端,可以让自己使用起来更加方便, ...

  4. Mac终端美化(iterm2+zsh+oh-my-zsh+powerlevel10k)

    iterm2+zsh+oh-my-zsh+powerlevel10k 一.下载iterm2 方式一:官网下载 https://iterm2.com/ 方式二:百度云下载 链接: https://pan ...

  5. 为MAC配置终端环境iTerm2+Zsh+oh-my-zsh

    首先展示下我的终端吧. 这就是我们为什么要配置iTerm2+Zsh+oh-my-zsh环境的原因: 我们使用zsh解释器,当然等你使用 zsh时就会知道zsh与bash对比的强大之处了. 至于我们的g ...

  6. iterm2 + zsh + oh-my-zsh +autojump

    iterm2  + zsh  +  oh-my-zsh +autojump 升级你的命令行工具,这个我折腾了好久,才明白了各个之间的关系. 1.先下载一个item2 首先你需要下一个iterm2,不要 ...

  7. Mac下iTerm2配置lrzsz功能

    Mac下iTerm2配置lrzsz功能 rz,sz是Linux/Unix同Windows进行ZModem文件传输的命令行工具. 优点就是不用再开一个sftp工具登录上去上传下载文件. 近期在mac上通 ...

  8. (转)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 ...

  9. mac 使用iTerm2快捷登录远程服务器

    mac 使用iTerm2快捷登录远程服务器 正常使用ssh登录服务器: ssh -p port user@host user@host's password: 输入端口,用户名,服务器ip地址后,还需 ...

随机推荐

  1. Java:Hibernate报错记录:Error executing DDL via JDBC Statement

    想着写一篇hibernate的博文,于是准备从头开始,从官网下了最新的稳定版本来做讲述. 结果利用hibernate自动建表的时候发生下面这个问题. 我很纳闷,之前用低版本一点的没有发生这个问题啊. ...

  2. Android Thread 官方说明

    Thread官方说明 https://developer.android.google.cn/reference/java/lang/Thread Thread是程序中执行的线程.Java虚拟机允许应 ...

  3. 智能ERP 交接班统计异常的解决方法

    请注意,有交接班统计数据不准确的需开启离线统计即可解决,交接班统计是按照结账时间来进行统计的 1.点击左侧导航栏中‘更多’-进入系统设置 2.进入营业设置后-开启离线统计-点击保存

  4. JMeter—总结

    Jmter简单总结 简单的使用篇 jmeter简单的使用 Jmeter中默认语言的显示 jmeter利用自身代理录制脚本 Jmeter运行后出现乱码 http cookie管理中cookie poli ...

  5. MSSQL coalesce系统函数简介

    转自:http://www.maomao365.com/?p=4390 一.coalesce函数简介 coalesce 系统函数,比ISNULL更强大,更方便的系统函数,coalesce可以接收多个参 ...

  6. 数据库之mysql篇(6)—— mysql常用函数函数/自定义函数

    常用函数 运算函数 我相信你都能看懂,所以以上的不再做过多解释 然后还有个,前面漏掉的between and: 意指10是否在0到20之间,如果是返回1,否则返回0 日期函数 这个要稍微注意一下参数, ...

  7. Incorrect key file for table错误解决方法

    问题现象: alter table portal_app_xxxx_xxx add devno varchar(64) NOT NULL DEFAULT '' COMMENT '设备机编',add s ...

  8. PHP的move_uploaded_file()出错解决

    今天用的PHP的move_uploaded_file方法保存前端上传的中文名称文件时,方法返回假,调试时错误码为2,错误信息为: move_uploaded_file(D:\ git_prj \ xx ...

  9. March 06th, 2018 Week 10th Tuesday

    Hope for the best, but prepare for the worst. 抱最好的愿望,做最坏的打算. To hope for the best and prepare for th ...

  10. CSS鼠标悬浮DIV后显示DIV外的按钮

    昨天写样式遇到个问题,如何让鼠标悬浮DIV后,显示DIV外的按钮,可以点击到按钮. 效果如下: 问题: 在DIV hover时候将按钮设为display: block,这是很直接的想法,但是这有个问题 ...