工利其器:mac篇

0. 基础安装

  • java >= 1.8
  • xcode
1
$ xcode-select --install

1. Homebrew https://brew.sh/

The missing package manager for macOS (or Linux)

1
2
3
4
5
6
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew install calc curl fd fzf httpie imagemagick jq rename tree wget zsh \
git-extras git-flow-avh pandoc snappy unar xz z zplug \
ant etcd maven go grpc protobuf pyenv \
mysql redis sqlite libressl openssl
$ brew upgrade libressl openssl

brew install 安装的程序:

  • calc 命令行下的计算器
  • curl http网页内容请求
  • wget The non-interactive network downloader. 支持续传
  • rename renames multiple files
  • unar 命令行下解压缩。可指定字符集解压zip内文件名带中文。

关闭brew的自动更新,设置环境变量

1
HOMEBREW_NO_AUTO_UPDATE=1

这样可以避免每次brew install时都执行update,太慢。
需要自己定期执行brew update获得最新的程序列表及版本。

2. iTerm2 https://www.iterm2.com/

iTerm2 is a replacement for Terminal and the successor to iTerm. It works on Macs with macOS 10.12 or newer. iTerm2 brings the terminal into the modern age with features you never knew you always wanted.

自定义设置

  • Preferences -> Profiles -> Keys
    • Load Preset…
    • 选择:Nextural Text Editing
    • 这样就可以支持用 CTRL + <CTRL + >跳转字符串了
  • Preferences -> Keys -> Hotkey
    • Show/hide iTerm2 with a system-wide hotkey 快捷键设置为:”command+.”

3. zsh

zsh可以作为bash的替代品。相比mac默认的bash,zsh有很多更强大更方便的功能。

1
2
3
4
$ brew install zsh zplug zsh-completions
$ vi /etc/shells
#设置zsh为默认,在文件末尾添加:/usr/local/bin/zsh
$ chsh -s /usr/local/bin/zsh

oh-my-zsh https://github.com/robbyrussell/oh-my-zsh

Oh My Zsh is an open source, community-driven framework for managing your zsh configuration.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ sh -c "$(wget -O- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
$ git clone git@github.com:igoradamenko/jira.plugin.zsh.git ~/.oh-my-zsh/custom/plugins/jira
$ git clone git@github.com:changyuheng/fz.git ~/.oh-my-zsh/custom/plugins/fz
$ vi ~/.zshrc
#修改plguins配置
plugins=(adb brew copydir copyfile cp dotenv docker docker-machine fd fzf osx urltools
git git-extras git-flow-avh golang httpie history jira mvn npm nvm spring
pip pyenv rsync vscode web-search xcode z zsh_reload)

# config by cf
export GOPATH=$(go env GOPATH)
PATH=$PATH:$GOPATH/bin

export JAVA_HOME=$(/usr/libexec/java_home)
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH

export JIRA_URL=http://jira.crazy1984.com
export JIRA_NAME=zhangjy
# extract JIRA issue name [ZNKFN-1234] from: feature/ZNKFN-1234_xyz
export JIRA_BRANCH_REGEX="s/[a-zA-Z]+\/([A-Z]+-[0-9]+)([^0-9].*)?/\1/p"

上边启用了一些非常有用的插件:

  • adb、brew、docker、mvn 命令的提示与补全(按TAB TAB)
  • git、git-flow-avh、jira(git与jira的自动关联) 命令的提示与补全
  • jira:注意要修改上述的JIRA_NAME配置,改成你的账号

4. git

修改 ~/.gitconfig 配置:一些UI颜色的设置,一些别名的配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[user]
name = "Your Name Here"
email = "your.email@crazy1984.com"
[color]
ui = auto
branch = auto
diff = auto
status = auto
[color "branch"]
current = green
local = yellow
remote = red
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = yellow
changed = green
untracked = cyan
[alias]
st = status
di = diff
ci = commit
co = checkout
br = branch
hist = log --graph --pretty=format:'%Cred%h%Creset %s%C(yellow)%d%Creset %Cgreen(%cr)%Creset [%an]' --abbrev-commit --date=relative
[core]
autocrlf = input
# display unicode file names
quotePath = false
[credential "https://git.yours.com"]
username = zhangjy
[http "https://git.yours.com"]
sslVerify = false

配置git的SSH Key

1
2
$ ssh-keygen -t rsa -C "your.email@crazy1984.com" -b 4096
$ pbcopy < ~/.ssh/id_rsa.pub

打开git web控制台:

  • 个人设置 => SSH Keys ,添加SSH Key,粘贴、保存。
  • 配置好SSH Key后,git clone使用ssh地址,pull和push的时候就不需要输入账户密码了

5. SDKMAN https://sdkman.io

SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates. Formerly known as GVM the Groovy enVironment Manager, it was inspired by the very useful RVM and rbenv tools, used at large by the Ruby community.

https://sdkman.io/install

1
2
3
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
$ sdk version