写完 “Ubuntu 自动化配置” 这篇文章后,每次连服务器心情指数都上升好几个百分点,因而想着应该将 macOs 的开发环境也梳理梳理,应该会对开发效率有所增益。
html
虽然Mac默认的终端已经很是强大,但从功能的丰富程度和开发效率上来看,对于我来讲iterm2无疑是更优选择。安装完毕后第一步就是开启 Hotkey-Window(Preferences→Keys→Create a Dedicated Hotkey Window),我习惯给其录制的快捷键是:Option+Space
,今后终端召之即来挥之即去,这能给予我一切尽在掌握之中的知足感。linux
如下三点我认为还需加以调整才能愉快玩耍:git
iterm2 默认的配色对蓝色不是很友好,特别是半透明的状况下很难看清楚,我通常将其颜色值改成:268bd2
,前景色直接设为白色,更改先后对比:
github
⌥ + ↔
本是向前或者向后跳过一个单词,可是却变成了这种字符 [D[C
,修复方法:在每一个窗口设置的 keys 中更改相应的快捷键,以下图:
shell
⌘ + T
为新建标签页,可是在 Hotkey-Window 中我须要新建同类别的标签页而不是默认,所以须要明确指定其快捷键:
vim
iterm2 功能丰富,然而不少是锦上添花,与其去记复杂的快捷键还不如多操做几步,我认为有必要去记的也就这么几个:ruby
⌘+N
、⌘+T
、⌘+↔
、⌘+F
、⌘+W
这几个快捷键就不解释了。⌘+D
垂直分屏、⌘+⇧+D
水平分屏、⌘+⌥+↑↓↔
切换分屏。⌘+↩
全屏、⌘ + R
清屏。⌃+A/E
行首/尾、⌃+R
查询历史命令。⌥+↔
左右跳过单词。记住这些就差很少了,脑容量有限,应能省则省。bash
使用 zsh
已经很长时间了,上篇文章 整理了一些 linux 中 bash 的配置,本想扩展一下使其知足 macOs 中更丰富的应用场景。但经历一番从开始到放弃以后,我决定从新整理一下 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)"
app
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"
大头来了,列举一些经常使用的:
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 }
当你的工做目录比较复杂的时候,这个插件的价值就体现出来了。它会读取历史记录,以后只要j dir
就能够愉快地跳转。安装也及其简单:brew install autojump
,而后编辑 .zshrc
文件,在插件选项中添加 autojump
便可。
我对它能够说是一见倾心,其实这个插件对于生产效率的提高并不明显,但耐不住看着舒服呀:
安装:git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
,后续步骤同上。
正如我记不住打包和压缩的命令,解压等命令也是如此,由于实在是不大经常使用。以前也是靠别名,直到发现这个插件统一了解压命令:x
。
它毫无疑问是 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 开发环境作一个概括,敬请期待。
个人公众号《有刻》,咱们共同成长!