Mac 的设置和软件 2018岁末版(2020.3更新)
Table of Contents
过几年换电脑就做一次,由于上一份工作不常用 Mac,需要安装一系列的东东,还挺折腾的,所以记录一下
MBP,iMac,iPhone,已经很普遍了,不像 10~20 年前,那是高大上的东西,现在网上各种相关资料很多。几大块,顺序不重要。工具和软件很多,把基本的先搞定。
键盘 & 鼠标 #
不得不吐槽,Apple 家的我极不习惯(用过至少两代了),键盘换成了 K1 Bluetooth:low profile,无线,低噪声,原生 Mac 布键(可以切换至 Windows),18 种酷炫夜光模式
2020 更新:K1 价廉物美,就是不耐操,疫情在家一年下来,电池很快掉电,键盘不灵敏了,几个常用键需要大力敲几次,MX Keys 已经替换上场:
鼠标换成了 Logi MX Master3(已升级到 3s, 8000dpi):
Mac 上的好鼠标太少,此前的用过两个雷神的 DeathAdder,基本寿命就是两年,手感,响应准确度等均弱于 MX Master3
以上两个东西性价比极好,网评可以看一波,至今我超级满意 。
电脑座椅也相当重要,值得投入。
MacOS 基本配置 #
System Preference #
Keyboard
功能键 Fn:默认情况下,F1-F12 都是特殊功能,比如调节屏幕亮度。而当你需要键入 F1-F12 时需要同时按住 Fn,这对于开发人员来说是非常不方便的。将 F1-F12 改成标准功能键。
键盘控制:上图里选 Shortcuts,然后 ✅ User keyboard navigation to move focus between controls
Caps 切换输入法
Dock
hot conners:
Finder #
Finder -> Preference -> Advanced:
Finder -> View -> Show View Options:
其它 #
macOS 默认只允许运行通过苹果应用商店下载的软件。macOS 如果想安装第三方应用需要到 Preference/系统偏好设置 > Security & Privacy/安全性与隐私 > General/通用 中开启,Allow apps downloaded from:🔘 Anywhere
Disable SIP(System Integrity Protection)
需要重启 Mac 进入 Recovery 模式(开机时同时按下 ⌘ R)
$ csrutil disable
$ reboot
重启后查看 SIP:
$ csrutil status
System Integrity Protection status: disabled
Disable Gatekeeper
macOS 如果想安装第三方未签名的应用需要在终端中执行命令行:
sudo spctl --master-disable
显示隐藏文件
希望在 Finder 里看到这个目录的内容
# show Library folder
chflags nohidden ~/Library
# show hidden files
defaults write com.apple.finder AppleShowAllFiles YES
# show path bar
defaults write com.apple.finder ShowPathbar -bool true
# show status bar
defaults write com.apple.finder ShowStatusBar -bool true
$ defaults write com.apple.finder _FXShowPosixPathInTitle true
$ killall Finder
screenshot
默认情况下,macOS Mojave 将屏幕截图存储在 Mac 的桌面上。现在,如果您启用了 iCloud 同步,那么它会不断上传到您的帐户。这是不安全的,也很占空间。
$ defaults write com.apple.screencapture location ~/Downloads
$ defaults write com.apple.screencapture type PNG
$ killall SystemUIServer
每次截图自带阴影效果,可以关闭或开启:
关闭
$ defaults write com.apple.screencapture disable-shadow -bool true; killall SystemUIServer
开启
$ defaults write com.apple.screencapture disable-shadow -bool false; killall SystemUIServer
其它很多设置,根据自己的喜好可以网上参考一番。
iTune/Music.app
Account -> Authorizations -> Authorize This Computer
MacOS 常用快捷键 #
众人皆知/常用:⌘ , ⌘ A ⌘ C ⌘ V ⌘ X ⌘ Z ⌘ R ⌘ F ⌘ N ⌘ ⇥ ⌘ ␣ ⌘ W ⌘ Q
系统通用
- 睡眠: ⇧ ⌘ ⏏
- 锁屏: ⌃ ⌘ Q
- 进入全屏模式:⌃ ⌘ F
- Character Viewer(弹出 emojis): ⌃ ⌘ ␣
- Show all windows of the front app: ⌃ ↓
- Show all windows: ⌃ ↑
- Forward delete: Fn del
- Paste without formatting: ⇧ ⌘ V
- Screenshot: ⇧ ⌘ 4 ␣(选择窗口)⇧ ⌘ 4 (选择区域)⇧ ⌘ 3(整个屏幕)
- 保存文件: ⌘ S
- 另存文件: ⇧ ⌘ S
- 在应用程序之间切换:⌘ ⇥
- 在单个应用程序的多个窗口之间切换:⌘ ~
- 新建窗口:⌘ N
- 隐藏窗口:⌘ H
- 最小化窗口:⌘ M
- 关闭当前窗口:⌘ W
- 退出: ⌘ Q
- 强行退出: ⌥ ⌘ Esc
Finder
- 打开 home folder: ⇧ ⌘ H
- 打开 desktop folder: ⇧ ⌘ D
- 打开文件、上级目录、下级目录:⌘O ⌘↑ ⌘↓
- 回到前一个目录: ⌘ [
- 转到下一个目录: ⌘ ]
- 隐藏文件的开关: ⇧ ⌘ .
软件 #
网上都有盗版或破解,需要花点时间找。Apple 的 MacOS 源自 Unix,但其自带系统软件难用,一二十年毫无大进步,和微软的 Windows 的用户体验差距不小,好在是第三方挺给力。
必备工具 #
Amphetamine:防止进入睡眠状态,定时休眠 🆓
App Cleaner & Unistaller:应用深度清理卸载
BetterZip,Archive Utility:压缩/解压缩
CleanMyMac,Lemon:垃圾清理,软件卸载,系统优化
键指如飞/FlyKey:列出了当前活动应用所有支持的键盘快捷组合键 🆓
Hidden Bar:菜单栏图标隐藏 🆓
Paralles Desktop:Windows 虚拟机,配合 PD Runner(原来挂在 Github 上,后来被毙了,可到 Gitee 上下载),解锁最新试用版 Paralles
Paragon NTFS for Mac:不用虚拟机,直接挂 NTFS,比较稳定了
Rectangle:开源版的 spectacle,和 Moom 类似管理窗口大小和定位,拖拽窗口即能定位,超级好用,配上快捷键 🈯️ 🆓
iTerms2,zsh,oh-my-zsh,Fig:命令行相关,见下
一些体会
- List of useful Quick Look plugins for developers
- Paralles:Windows 对 MBP 的 Retina 的支持不好,DPI 不可以超过 185%,参见 Resize Search Box and Address Box Win7
- Paralles:在 Windows 里删除 shared folder 里的文件(非挂靠在 Windows 的硬盘),不会进入 Windows 回收站
- Moom 的快捷窗口操作(Rectangle 取代):
- Aflred/Raycast 据说是个神器,spotlight+,可迅速定制各种任务的快捷方式,我并没有使用。
- Apple 会把 TNT 的证书删除,碰到软件打不开的问题,需要自行重新签发证书:
> codesign --force --deep --sign - /Applications/xxx.app
常用软件 #
- Adobe Acrobat,PDF Expert:PDF 老东家,还是比 PDF Expert 好用,只是软件太臃肿
- Beyond Compare:文件对比比较神器
- Bob 🆓:屏幕取词,截图翻译
- Boom3D:音效加强
- NeatReader 🆓:各种电子书(epub,chm,等常用格式)阅读器
- Dash 🆓:编程文档
- VDown 🆓:各种视频下载,支持优酷、腾讯视频、bilibili、土豆、爱奇艺、网易、搜狐、微博以及国外的 Youtube 等等
- Find My 🆓:跟踪 Apple 设备,防止遗失
- Folx Pro:各种 p2p 下载
- GoodNote:手写体笔记
- magnetw:开源种子搜索神器(已经关闭 😭)
- Movist Pro:Mac 上最好的 movie 播放器
- PopClip:Copy/Paste 剪贴板工具
- Reeder:rss 订阅
- Screenshot 🆓,Shottr 🆓:截图
- Omi,ScreenFlow:录屏
- Sketch:矢量画图
其它常用软件:
- Chrome 及一堆插件(Goolge 同步)
- Windows Office for Mac
- 各种网盘软件:百度网盘、Dropbox、Google Drive 等
- 微信 Wechat,Whatsapp,Telegram,Twitter,Discord,Slack,Zoom,Teams 等一众社交软件
开发工具 #
JetBrain 的全家桶 IntelliJ,Pycharm,WebStorm,Goland,DataGrip是我十多年来开发 Java 和其它语种的主力 IDE,各种文本编辑基本已归置 VS Code 和 强大的 Notepad++(Windows only)。Windows 上经常画图的工具是 Visio,慢慢转到 Excalidraw 和 draw.io。
vi/vim 我是半吊子,非常有空才打算深入。
VPN #
七款 VPN 比较:
VPN 名称 | 注册 | 可连接国家 | 限速 | 用量 | 使用设备 | 广告 | P2P |
---|---|---|---|---|---|---|---|
AtlasVPN | 不要 | 3 | 🈶️ | 无限制 | 1 | 🈚️ | 是 |
Hotspot Shield | 不要 | 1 | 🈶️ | 500MB/天 | 1 | 🈶️ | 是 |
PrivadoVPN | 要 | 12 | 🈚️ | 10GB/月 | 1 | 🈚️ | 是 |
ProtonVPN | 要 | 3 | 🈶️ | 无限制 | 1 | 🈚️ | 否 |
Speedify | 不要 | 几乎全部 | 🈚️ | 1GB/月 | 1 | 🈚️ | 否 |
TunnelBear | 要 | 23 | 🈚️ | 500MB/天 | 1 | 🈚️ | 是 |
Windscribe | 要 | 10 | 🈶️ | 10GB/月 | 1 | 🈚️ | 否 |
命令行 #
命令行各种配置的保留,参考之前的文章: dotfiles - 你肯定知道这个东西是什么,不然就不要往下看了
命令行的东西比较杂,主要有那么几大件:
- homebrew:软件安装管理必备神器,相当于 Linux 上的 yum,装完后一通 brew cask install 和 brew install
- zsh oh-my-zsh
OMZ
:OMZ 是个 zsh 的集成者 - iTerm2:比 Mac 自带的 terminal 强,颜色 aura-theme-soft,字体 Cascadia Code PL,窗体,快键唤出等等,自行安装和设置。另外可以配合 tmux 多窗口管理器使用。
- Fig:命令行自动补全神器
brew #
brew 的备份和迁移 #
brew 可以通过 brew bundle 进行备份,然后一键在另外一台机器上恢复:
Brewfile 和通常的 brew 略有不同:
命令行 | Brewfile |
---|---|
brew install [formulaName] | brew “[forumlaName]” |
brew cask install [caskName] | cask “[caskName]” |
mas install [identifier] | mas “[bundleIdentifier]”, id: [identifier] |
恢复/安装:
$ brew bundle
各种有用的工具 #
有许多增强型命令行工具,并善用命令行的 alias,例如:
ag 搜索工具,类似 ack,但更快
asciinema 可以录制 terminal
bat 增加语法高亮,取代 cat
broot 取代 tree
choose 结合 cut 和 awk 功能
curlie 简化 curl
dust Rust 开发,取代 du
exa 取代 ls
fd 更快,更友好,取代 find
fig 命令行自动补全
fzf 文件模糊搜索,参考 Vim universe. fzf - command line fuzzy finder
gping 取代 ping
hyperfine benchmark/测速工具
htop 取代 top 类似的还有gtop
httpie 命令行 http,类似 wget,curl
jq json 文件浏览、格式化、支持高亮,有一点学习曲线,看参考 jq cheetsheet 和来自 文档的一些使用技巧
procs 显示 PID 和 TCP 端口,取代 ps,用 Rust 开发
psgrep 取代 ps aux | grep
pstree Linux 上移植过来,树型方式显示进程
ripgrep 更快,更友好,和 grep 类似但遵循 gitignore
sd 取代 sed
shellcheck shell script 语法检查
thefuck 神器
tldr 取代 man
xh 与 httpie 简洁界面类似,但速度更快
xz 压缩工具
参考 Julia Evans 的 A list of new(ish) command line tools
zsh #
plugins #
zsh 的插件很多,自行选择 awesome-zsh-plugins:
zsh-syntax-highlighting
zsh-history-substring-search
命令行提示符 #
OMZ Theme 自带的和那个 Powerlevel10K 太眼花缭乱,这个简约 spaceship
alias #
alias
### =======
### Alias
### =======
# brew
alias b="brew"
alias bdump="rm ~/Brewfile; brew bundle dump; dotadd ~/Brewfile; dotcmt; dotpush"
alias bls="brew list --versions"
alias bll="brew deps --tree --installed"
alias bsearch="brew search"
alias binfo='f_binfo(){brew info "$1"; brew uses --recursive --installed "$1"}; f_binfo'
alias bold="brew outdated"
alias badd="brew install"
alias bdel="brew uninstall"
alias blnk="brew link --overwrite"
alias bupd='echo "updating brew formulas and casks ....."; brew update; brew outdated --verbose; brew upgrade; brew cleanup --prune=all; brew doctor --verbose; brew outdated --cask --verbose; brew upgrade --cask; brew doctor --verbose'
alias bsvc="brew services list"
alias bstart="brew services start"
alias bstop="brew services stop"
alias brestart="brew services restart"
### Java
###
export JAVA_HOME=`/usr/libexec/java_home -v 11`
export JAVA_OPTS=
alias j="java"
alias jc="javac"
alias jj="java -jar"
# shows the statck trace of a specified java process id
alias jps="jps -l"
# maven
export M2_HOME=/usr/local/Cellar/maven/3.9.0/libexec
export MAVEN_HOME=$M2_HOME
export M2_OPTS=
alias mvnc="mvn clean"
alias mvni='mvn clean install -Dmaven.test.skip=true'
alias mvnt='mvn test'
alias mvnp='mvn package'
# gradle
export GRADLE_HOME=/usr/local/Cellar/gradle/8.0/libexec
# Default is `"/(build|integTest|out)/"`
export GRADLE_COMPLETION_EXCLUDE_PATTERN="/(build|integTest|samples|smokeTest|testFixtures|templates|out|features)/"
# Essentially turn off checking for changed scripts
export GRADLE_COMPLETION_EXCLUDE_PATTERN="gradle"
export GRADLE_COMPLETION_UNQUALIFIED_TASKS="true"
alias gr="./gradlew --daemon --parallel --no-build-cache"
alias grclean="./gradlew clean"
alias grbuild="./gradlew build"
alias grboot="./gradlew bootRun"
jdk() {
if [ ! -n "$1" ]; then
/usr/libexec/java_home -V 2>&1
else
export JAVA_HOME=`/usr/libexec/java_home -v $1`
echo "JAVA_HOME switched to '$JAVA_HOME'."
export PATH="$JAVA_HOME/bin":$PATH
fi
}
javaver() {
echo "⌘ Java ⌘" | lolcat
jdk | lolcat
java -version | lolcat
echo
mvn -v | lolcat
echo
gradle -v | lolcat
echo
}
scalaver() {
echo "⌘ Scala ⌘" | lolcat
scala --version | lolcat
sbt -V | lolcat
echo
}
### Javascript
###
# node, npm
alias n="npm"
alias nconf='nocorrect npm config ls -l'
alias ninit="npm init"
alias nls="npm list"
alias nls0="npm list --depth=0"
alias nls1="npm list --depth=1"
alias nls2="npm list --depth=2"
alias nls3="npm list --depth=3"
alias nlsg="npm list -g"
alias nlsp="npm list --prod"
alias nlsd="npm list --dev"
alias nold="npm outdated"
alias noldg="npm outdated -g"
alias nsearch="npm search"
alias ninfo="npm info"
alias nadd="npm install -S"
alias naddd="npm install -D"
alias naddg="npm install -g"
alias ndel="npm uninstall"
alias ndelg="npm uninstall -g"
alias nupd="npm unpdate"
alias nupdg='echo "updating node global modules ......"; npm cache verify; npm outdated -g; npm update -g; npm fund; npm audit fix --force; npm cache clean --force; npm doctor;'
alias nrun="npm run"
alias nbuild="npm run lint && npm run build && npm doctor"
alias ntest="npm run test"
alias npub="npm run build && npm publish"
alias nclean="npm cache clean --force"
alias ngraph='depcruise --max-depth 2 --exclude "^node_modules" --output-type dot src | dot -T svg > dependencyGraph.svg'
alias nx="npx"
# pnpm
export PNPM_HOME="/Users/zhonglun/Library/pnpm"
case ":$PATH:" in
*":$PNPM_HOME:"*) ;;
*) export PATH="$PNPM_HOME:$PATH" ;;
esac
alias pn="pnpm"
alias pnconf="pnpm config list -g"
alias pninit="pnpm init"
alias pnls="pnpm list"
alias pnls0="pnpm list --depth=0"
alias pnls1="pnpm list --depth=1"
alias pnls2="pnpm list --depth=2"
alias pnlsp="pnpm list --prod"
alias pnlsd="pnpm list --dev"
alias pnold="pnpm outdated"
alias pnwhy="pnpm why"
alias pnsearch="pnpm search"
alias pninfo="pnpm info"
alias pni="pnpm install"
alias pnadd="pnpm add"
alias pnaddd="pnpm add -D"
alias pndel="pnpm rm"
alias pnupd="pnpm update"
jsver() {
echo "⌘ JS ⌘" | lolcat
echo "Node version: $(node -v)" | lolcat
echo "NPM version: $(npm -v)" | lolcat
echo
}
### Go
###
export GOPATH=/Users/fastzhong/go
export GOROOT=/usr/local/opt/go/libexec
export GO111MODULE="on"
gover() {
echo "⌘ Go ⌘" | lolcat
go version | lolcat
echo
}
### Python
###
# pyenv
export PYENV_HOME=$HOME/.pyenv
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
alias pyls="pyenv install -l"
alias pyglobal="pyenv global"
alias pyadd="pyenv install"
alias pydel="pyenv uninstall"
# python
alias p="python"
alias ppath='f_pypath() {export PYTHONPATH=$1:$PYTHONPATH;}; f_pypath'
alias pylint="pylint --quiet"
alias pytest="pytest --quiet"
alias pipadd="pip install"
alias pipdel="pip uninstall"
alias pipupd='echo "updating all python packages ....."; sudo pip install -U pip && pip freeze --local | grep -v "^\-e" | cut -d = -f 1 | xargs pip install -U; rm ~/.pip/cache/*'
# poetry
alias ptcfg="poetry config --list"
# init a project
alias ptinit="poetry init && cat pyproject.toml"
# activate project virtual env
alias ptshell="poetry env info && poetry shell"
# install all in pyproject.toml
alias ptls="poetry show --tree"
alias ptinstall="poetry install"
alias ptadd="poetry add"
alias ptdel="poetry remove"
alias ptold="poetry show --outdated"
alias ptupd="poetry update"
alias ptbuild="poetry build"
alias ptpub="poetry publish"
pyver() {
echo "⌘ Python ⌘" | lolcat
pyenv versions | lolcat
echo
}
### Lua
###
export OPENRESTY_HOME="/usr/local/opt/luajit-openresty"
export PKG_CONFIG_PATH="/usr/local/opt/luajit-openresty/lib/pkgconfig"
### Ruby
###
export GEM_HOME="$HOME/.gem"
alias gemupd='echo "updating ruby gems ....."; sudo gem update --system && gem cleanup'
# git
alias g="git"
# visualize git changes
alias gsim="git-sim"
alias gconf="nocorrect git config --list"
alias gignore="git check-ignore -v"
# branch sorted by last modified
alias glocal="git branch -vv --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) %(color:green)(%(committerdate:relative)) [%(authorname)] - %(contents:subject)' --sort=-committerdate"
alias gremote="git fetch -t --all && git branch --remotes --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) %(color:green)(%(committerdate:relative)) [%(authorname)] - %(contents:subject)' --sort=-committerdate"
alias gdev="git checkout develop && git pull"
alias gmaster="git checkout master && git pull"
alias gtrack="git fetch --all && git for-each-ref --format='%(refname:short)' refs/remotes/origin | sed 's@\(origin/\)\(.*\)@\2\t\1\2@' | xargs -n 2 git branch --track && glocal"
# deletes all local branches that have already been merged to develop
alias gmerged="git checkout develop && git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d"
# git checkout (existing branch/remote branch/new branch)
f_git_checkout() {
branch=${1}
if [ ! -z "$branch" ]; then
existed_in_local=$(git branch --list ${branch})
if [[ -z ${existed_in_local} ]]; then
echo "Git branch '$branch' NOT in local repository"
git fetch origin
existed_in_remote=$(git ls-remote --heads origin ${branch})
if [[ -z ${existed_in_remote} ]]; then
echo "Git branch '$branch' NOT in the remote repository"
# new branch: create it
git checkout -b $branch
else
echo "Git branch '$branch' in the remote repository"
# remote branch: checkout and track it
git switch $branch
fi
else
# existing branch
git checkout $branch
fi
else
echo "Error: branch name not specified"
fi
}
alias gco="f_git_checkout"
# git switch with changes (staged and unstaged, but not untracked)
f_git_switch() {
BranchName=$1
if [ ! -z "$BranchName" ]; then
if [ $(git branch -l | grep $BranchName) ]; then
git stash
git switch $BranchName
git stash pop
else
git stash
git switch -c $BranchName
git stash pop
fi
else
echo "Branch name is not specified"
fi
}
alias gswt="f_git_switch"
# git commit
alias gadd="git add"
alias gcmt="git commit -m"
alias gall="git add -A && git commit -m"
alias gsave="git commit -a -m 'chore: SavePoint'"
alias gwip="git commit -a -m 'chore: WIP'"
alias gdone="git commit -a -m 'Done'"
# git stash
alias gstash="git stash"
alias gstashadd="git stash -u"
alias gstashdel="git stash drop"
alias gstashls="git stash list && git stash show"
alias gstashpop="git stash pop"
# git undo
alias gamd="git commit --amend"
alias gundo="git reset --hard HEAD"
alias glast="git reset --soft HEAD~1"
alias grevert="git revert"
# git stat & log
alias gdiff="git diff --name-status"
alias gstat="git status"
alias gshow="git show --stat"
alias glog="git log --oneline --decorate --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%an%C(reset)%C(bold yellow)%d%C(reset) %C(dim white)- %s%C(reset)' --all"
alias glogremote='currentBranch=$(git symbolic-ref --short -q HEAD) && git log "$currentBranch"..origin/"$currentBranch" --oneline'
# tag
alias gtag="git log --no-walk --tags --pretty=format:' %C(yellow)%h %Cgreen%d %Cred%ad %Creset%s' --date=local"
# git pull & push
alias gpull="git fetch && git merge"
alias gpush='currentBranch=$(git symbolic-ref --short -q HEAD) && git diff --name-status "$currentBranch" origin/"$currentBranch" && git pull && git push'
alias gpushtrack='git push -u origin'
alias grebase="git checkout develop && git pull && git checkout - && git rebase -i develop"
alias grebasecnt="git rebase --continue"
# git submodule
alias gm="git submodule"
f_git_mod_update() {
git submodule foreach --recursive git checkout develop
git submodule foreach --recursive git pull origin develop
git add -A
git commit -m "update submodules $(date +'%d/%m/%Y')"
}
alias gmupd="f_git_mod_update"
f_git_mod_add() {
git submodule add "$1" "$2"
git submodule init
git submodule update --remove --recursive
}
alias gmadd="f_git_mod_add"
f_git_mod_del() {
git submodule deinit -f "$1"
rm -rf .git/modules/"$1"
git rm -rf "$1"
}
alias gmdel="f_git_mod_del"
# caution: delete untracked files
alias gdel="git clean -nxfd"
alias gdelx="git clean -xfd && git gc --auto"
alias gpack="git repack && git prune-packed && git reflog expire --expire=1.month.ago && git gc --aggressive"
# daily standup
alias gstandup='git standup -a "all" -d 3'
# Ansible
alias a="ansible"
# Terraform
alias tf="terraform"
# Docker
alias dk='docker'
alias dkclean='docker ps -q -a -f status=exited | xargs -r docker rm && docker images -q -f dangling=true | xargs -r docker rmi && docker builder prune -a'
alias dkcleanx='docker system prune -af'
alias dkbuild="DOCKER_BUILDKIT=1 docker build ."
alias dkexe="docker exec --it"
alias dkps="docker ps -a"
alias dcbuild="DOCKER_BUILDKIT=1 docker compose build"
alias dcstart="docker compose start -f"
alias dcstop="docker compose stop"
alias dcup="docker compose up -d"
alias dcdown="docker compose down"
alias dclog="docker compose logs -f"
# Kubernetes
# kubectl autocomplete
alias k="kubecolor"
alias kctl="kubectl"
alias kcfg="nocorrect k config view"
alias ktell="kubectl explain"
alias kctx="kubectx"
alias kns="kubens"
alias knsnew="kubectl create namespace"
alias ktree="kubectl tree"
alias knp="kubectl np-viewer"
alias kpods="kubectl get pods"
alias ksvcs="kubectl get services"
alias ksh='kubectl run -it --image bash --restart Never --rm shell'
alias krbac="kubectl rbac-tool analysis --cluster-context"
alias kwhocan="kubectl rbac-tools who-can"
alias krole="kubectl rolesum"
alias kcani="kubectl rakkess"
alias kcanit="kubectl rakkess --as"
alias kdbg="kubectl debug"
# kubectl get resource
alias kgnode="kubectl get nodes -o wide"
alias kgpod="kubectl get pods -o wide"
alias kgdpm="kubectl get deployments -o wide"
alias kgsvc="kubectl get svc -o wide"
# kubectl describe resource
alias kdnode="kubectl describe node"
alias kddpm="kubectl describe deployment"
alias kdpod="kubectl describe pod"
alias kdsvc="kubectl describe svc"
# krew
# stern
### misc.
alias c="bat"
alias cdls='f_cdls(){cd "$1" && eza -lh}; f_cdls'
alias cddown="cd ~/Downloads; eza -lh"
alias cdwork="cd ~/workspace; eza -lh"
alias cdoss="cd ~/workspace/oss; eza -lh"
alias cdmy="cd /Volumes/MySpace2021/; eza -lh"
alias cdmywork="cd /Volumes/MySpace2021/workspace; eza -lh"
alias delstore="find . -type f -name '*.DS_Store' -ls -delete"
alias df="df -ahP | column -t"
alias diff="colordiff"
alias du="du -shx */ | sort -h"
alias e="echo"
alias f="fd"
alias finder="open -a Finder"
alias free='free -m -h'
alias egrep="egrep --color=auto --exclude-dir={.bzr,CVS,.git,.hg.svn}"
alias fgrep="fgrep --color=auto --exclude-dir={.bzr,CVS,.git,.hg.svn}"
alias h="history | grep"
alias help="tldr"
# ls
alias l="eza -1 -a --group-directories-first"
alias ld="eza -lD"
alias lf="eza -lF --color=always"
alias ls="eza -lh"
alias ll="eza -lah --group-directories-first"
alias lt1="eza -T --level=1"
alias lt3="eza -T --level=3"
alias lt5="eza -T --level=5"
alias lgt='f_lgt(){eza -lah --git --git-ignore --tree --level="$1"}; f_lgt'
alias listen='lsof -PiTCP -sTCP:LISTEN'
alias mkcd='f_mkcd(){mkdir -pv "$1"; cd "$1"}; f_mkcd'
alias mnt="mount | column -t"
alias myip="curl -s http://checkip.dyndns.org/ | sed 's/[a-zA-Z<>/ :]//g'"
alias ports="netstat -n -a -p tcp | grep LISTEN"
alias routes="netstat -nr"
alias path='echo -e ${PATH//:/\\n}'
alias psg="ps aux | grep -v grep | grep -i"
alias ping="prettyping --nolegend"
alias q="exit"
alias rg="ripgrep"
### ssh
alias s="ssh"
alias sshls="grep 'Host ' ~/.ssh/config | awk '{print $2}' | sort -h"
alias today='date +"%A, %B %d, %Y"'
alias top="htop"
alias x="open -a '/Applications/XCode.app'"
alias z="source ~/.zshrc"
alias _=sudo
alias -g grep="grep -i --color=auto --exclude-dir={.bzr,CVS,.git,.hg.svn}"
alias -g G="| grep"
alias -g L="| less"
alias -g H="| head"
# pskill foo: dangerous function to kills all processes matching foo
pskill() {
procs $1 --no-header --only pid | xargs kill -15
}
eval "$(thefuck --alias fuck)"
# vs code
alias codegit="code ~/.gitconfig"
alias codeignore="code ~/.gitignore"
alias codessh="code ~/.ssh/config"
alias codevim="code ~/.vimrc"
alias codezsh="code ~/.zshrc"
alias codestarship="code ~/.config/starship.toml"
alias codeblog="code /Users/fastzhong/workspace/blog/blog.code-workspace"
iTerm2 #
iTerm2 -> Install Shell Integration
selection #

自带快捷键 #
Function | Shortcut |
---|---|
New Tab | ⌘T |
Close Tab or Window | ⌘ W same as many mac apps |
Go to Tab | ⌘ Number ie: ⌘ 2 is 2nd Tab |
Go to Split Pane by Direction | ⌘ ⌥ → ⌘ ⌥ ← |
Cycle iTerm Windows | ⌘ ` true of all mac apps and works with desktops/mission control |
Splitting | |
Split Window Vertically (same profile) | ⌘ D |
Split Window Horizontally (same profile) | ⌘ ⇧ D |
Moving | |
Move a pane with the mouse | ⌘ ⌥ ⇧ and then drag the pane from anywhere |
Fullscreen | |
Fullscreen | ⌘ Enter |
Maximize a pane | ⌘ ⇧ Enter use with fullscreen to temp fullscreen a pane |
Resize Pane | ⌃ ⌘ ↑ ⌃ ⌘ ↓ given you haven’t mapped this to something |
Less Often Used By Me | |
Go to Split Pane by Order of Use | ⌘ ] ⌘ [ |
Split Window Horizontally (new profile) | ⌥ ⌘ H |
Split Window Vertically (new profile) | ⌥ ⌘ V |
Previous Tab | ⌘ ← |
Next Tab | ⌘ → |
Go to Window | ⌘ ⌥ Number |
shell 常用的快捷键 #
自定义快捷键:
快捷键 | 命令 | 发送 | 字符 |
---|---|---|---|
⌥ ← | 左移一个单词 | Escape Sequence | b |
⌥ → | 右移一个单词 | Escape Sequence | f |
⌘ → | 移至行首 | Hex Codes | 0x01 |
⌘ ← | 移至行尾 | Hex Codes | 0x05 |
⌥ ⌫ | 删除至词首 | Hex Codes | 0x17 |
⌘ ⌫ | 删除整行 | Hex Codes | 0x15 |
⌘ Z | undo | Hex Codes | 0x1f |
iTerm2 技巧 #
- iTerm2 允许我们快速查看剪贴板内容 只需使用 ⌘ ⇧ H 可以呼出粘贴历史
- 在 iTerm2 中,双击选中,三击选中整行,四击智能选中(智能规则可配置)
- 按住 ⌘ 键:可以拖拽选中的字符串
- 点击 url:调用默认浏览器访问该网址;
- 点击文件:调用默认程序打开文件;
- 点击文件夹:在 finder 中打开该文件夹;
- 同时按住 ⌥ 键,可以以矩形选中,类似于 Vim 中的 ⌃ V 操作
- 将文本内容复制到剪切板
- 在 Finder 中打开当前目录
session 恢复 #
system preferences - general:
iTerm2 - settings - General:
vi 快捷键 & 技巧 #
把 bindkey -v 加到 .zshrc 里,命令行就可以用 vi 的快捷键(bindkey -e 则是 emacs)。
注意如果使用 vi 快捷键,其它常规的就会失效。
快速移动 #
Function | Shortcut |
---|---|
Move to the start of line | ⌃ A 或者 ⌃ Home |
Move to the end of line | ⌃ E 或者 ⌃ End |
Move forward a word | ⌥ F |
Move backward a word | ⌥ B |
Set Mark | ⌘ M |
Jump to Mark | ⌘ J |
Moving by word on a line (this is a shell thing but passes through fine) | ⌃ ← ⌃ → |
Cursor Jump with Mouse (shell and vim - might depend on config) | ⌥ Left Click |
Copy & Paste #
Function | Shortcut |
---|---|
Enter Copy Mode | ⇧ ⌘ C |
Enter Character Selection Mode in Copy Mode | ⌃ V |
Move cursor in Copy Mode | H J K L vim motions or arrow keys |
Copy text in Copy Mode | ⌃ K |
命令行历史 #
Function | Shortcut |
---|---|
Search as you type | ⌃ R and type the search term; Repeat ⌃ R to loop through result |
Search the last remembered search term | ⌃ R twice |
End the search at current history entry | ⌃ Y |
Cancel the search and restore original line | ⌃ G |
常用 #
Function | Shortcut | Use |
---|---|---|
Delete to start of line | ⌃ U | Use this to start over typing without hitting ⌃ C |
Delete to end of line | ⌃ K | Use this with command history to repeat commands and changing one thing at the end! |
Repeat last command | ↑ ↓ | Cycle and browse your history with up and down. ⌃ R is faster if you know the string you are looking for. |
Move back and forth on a line | ← → | This takes you off the home row but it’s easy to remember |
Move back and forth on a line by words | ⌥ ← ⌥ → | Fast way to jump to a word to correct a typo or “run again” with minor changes |
Delete previous word (in shell) | ⌃ W | It’s faster to delete by words. Especially when your last command was wrong by a single typo or something. |
Clear screen | ⌃ L | This is telling the shell to do it instead of an explicit command like clear or cls in DOS. If you use ⌘ K, this is telling iTerm to clear the screen which might have the same result or do something terrible (like when using a TUI like top or htop . In general, use this instead of typing clear over and over. |
⌘ K 与 ⌃ L 的区别
一个区别是 ⌘ K 清除回滚缓冲区以及屏幕。 ⌃ L 仅清除屏幕,有效地将屏幕上的内容“向上”移动到回滚缓冲区中。
另一个区别是 ⌃ L 是由终端内运行的进程执行的。例如,bash 将清除屏幕并重新绘制提示符,包括其中任何未完成的命令。其他程序可能继续刷新而不是先清除屏幕。另一方面, ⌘ K 由终端本身执行,无论窗口中运行什么,因此它可能会隐藏程序的输出。
巨量资源 #
🛒 购买 MacRumors Buyer’s Guide:非常实用,购买苹果产品前必看
🛒 命令行
- awesome cli apps:A curated list of command line apps
- awesome shell:A curated list of awesome command-line frameworks,toolkits,guides and gizmos
- awesome-macos-command-line:收集了很多有趣的 Mac 终端命令
🛒 软件介绍
- 零度解说:各种免费资源,开车资源
- awesome-mac 软件大集合:收集各种类别非常好用的 Mac 应用程序、软件以及工具
🛒 软件下载
MacWk.com 精品 Mac 应用(已经关闭 😭)
