Mac 小记 — iTerm2、Zsh、Homebrew
来源:捷义     阅读:604
蜂鸟
发布于 2018-12-12 23:42
查看主页

前言

写完 “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 功能丰富,然而很多是锦上添花,与其去记复杂的快捷键还不如多操作几步,我认为有必要去记的也就这么几个:

记住这些就差不多了,脑容量有限,应能省则省。

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'_=sudoafind='ack -il'd='dirs -v | head -10'g=gitga='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=gguggpush='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_prettilyglum='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=sudopo=popdpu=pushdrd=rmdirrun-help=manwhich-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 packagebrew uninstall package# 下载第三方应用brew cask install qqbrew cask uninstall qq

有必要记录的是更换镜像源,我选择的是中科大镜像:

# 替换 brew.git:#  Homebrew/brewcd "$(brew --repo)"git remote set-url origin https://mirrors.ustc.edu.cn/brew.git# 替换 homebrew-core.git:#  Homebrew/homebrew-corecd "$(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' >> ~/.zshrcsource ~/.zshrc

结语

以上三个软件是我认为拿到 mac 起就必需安装配置的,无论这台 mac 将被用于什么业务,这是愉快玩耍 macOs 的基础。后续若有空我会将我个人的 macOs 开发环境做一个归纳,敬请期待。


我的公众号《有刻》,我们共同成长!


免责声明:本文为用户发表,不代表网站立场,仅供参考,不构成引导等用途。 系统环境 服务器应用
相关推荐
[ WWDC2018 ] - ARKit2 革新 What’s New in ARKit 2
你还不懂可见性、有序性和原子性?
mybatis模糊查询防止SQL注入(很详细)
JS(六)作用域(链)及词法作用域---闭包前置知识
深入 Nginx:我们是如何为性能和规模做设计的
首页
搜索
订单
购物车
我的