虽然有 Time Machine 这样的神器,但是它不方便共享,所以这里记录下我在 Mac 下的一些常用环境。

不定期更新。

Tools

Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Oh My ZSH

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

插件

安装自动提示、高亮插件。

brew install zsh-autosuggestions
brew install zsh-syntax-highlighting

启用插件,包含 ZSH 自带和通过 Homebrew 安装的。

plugins=(
    git autojump iterm2 brew copyfile extract sublime colored-man-pages
)

source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh

主题

更多见:https://github.com/robbyrussell/oh-my-zsh/wiki/Themes

ZSH_THEME="af-magic"

Autojump

brew install autojump

Tcping

brew install tcping

Htop

brew install htop

Jq

brew install jq

Tree

brew install tree

Ag

brew install ag

MyCLI

brew install mycli

Icdiff

brew install icdiff

CCAT

brew install ccat

Parallel

brew install parallel

V2Ray

brew install v2ray-core

Speedtest

brew install speedtest-cli

SSHPass

brew install http://git.io/sshpass.rb

Supervisor

brew install supervisor

Alias

# 查询本地和外网IP
alias ip='echo 本地 IP:$(ipconfig getifaddr en0) && curl https://myip.ipip.net'
# 一键更新 brew
alias brew_update='brew update && brew upgrade && brew cu -a -f  -y && brew cleanup'
# 开启命令行代理
alias proxy_on='export http_proxy=socks5://127.0.0.1:1081; export HTTP_PROXY=$http_proxy; export https_proxy=$http_proxy; export HTTPS_PROXY=$http_proxy;'
# 关闭命令行代理
alias proxy_of='unset http_proxy;unset HTTP_PROXY;unset https_proxy;unset HTTPS_PROXY'
# 生成指定长度密码
alias gen_password='gen_password(){ LC_ALL=C tr -dc "[:alnum:]" < /dev/urandom | head -c $1}; gen_password $1'
# 快速配置 Git 环境
alias git_config_self='git config user.email "xxx" && git config user.name "xxx"'
# 搭配 ZSH 的 git 插件使用,git diff 更直观
alias gd='git icdiff'
# 支持 cat 带颜色输出
alias cat='ccat'
# 快捷脚本
alias code_init='~/init.sh' 
alias code_update='~/update_all.sh'

Scripts

init.sh

并行同步目录下所有项目至远程仓库最新代码,同时精简分支数只保留 master 分支

#!/bin/bash
ls -l |grep "^d" |awk '{print $9}' | parallel git -C {} checkout master

ls -l |grep "^d" |awk '{print $9}' | parallel "git -C {} branch | grep -v master | xargs -t git -C {} branch -D"

ls -l |grep "^d" |awk '{print $9}' | parallel "git -C {} fetch --all && git -C {} reset --hard origin/master && git -C {} pull"

update_all.sh

并行更新目录下当前分支代码并安装 composer 依赖

 #!/bin/bash

 function green(){
     echo -e "\033[32m~~~~~~~~~~~~$1~~~~~~~~~~~~\033[0m"
 }

 function update(){
 folder=$1
 green "Update $folder code"
 git -C $folder pull
 if [[ -e "$folder/composer.lock" ]]
 then
     green "Update $folder composer"
     composer install -d $folder -o
 else
     green "Not found composer"
 fi
 }

 export -f update
 export -f green

 ls -l |grep "^d" |awk '{print $9}' | parallel update

Brew Summary

brew install zsh-autosuggestions zsh-syntax-highlighting autojump tcping htop jq tree ag mycli icdiff ccat parallel v2ray-core speedtest-cli http://git.io/sshpass.rb supervisor
brew cask install typora iina sublime-text docker shuttle postman sequel-pro kindle istat-menus telegram CheatSheet lulu sourcetree