🗂 目录

Mac 的设置和软件 2018岁末版(2020.3更新)

December 31, 2018 • 预计阅读时间 13 分钟

过几年换电脑就做一次,由于上一份工作不常用 Mac,需要安装一系列的东东,还挺折腾的,所以记录一下。

💬 MBP,iMac,iPhone,已经很普遍了,不像 10~20 年前,那是高大上的东西,现在网上各种相关资料很多。几大块,顺序不重要。工具和软件很多,把基本的先搞定。

键盘 & 鼠标

不得不吐槽,Apple 家的我极不习惯(用过至少两代了),键盘换成了 K1 Bluetooth :low profile,无线,低噪声,原生 Mac 布键(可以切换至 Windows),18 种酷炫夜光模式

2020 更新:K1 价廉物美,就是不耐操,疫情在家一年下来,电池很快掉电,键盘不灵敏了,几个常用键需要大力敲几次,MX Keys 已经替换上场:

mx-keys

鼠标换成了 Logi MX Master3 (已升级到3s):

mx-master-3
mx-master-settings mx-master-settings

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 切换输入法

keyboard

✦ Dock

dock

Finder

Finder -> Preference -> Advanced

Finder-Advanced

Finder -> View -> Show View Options

Finder-ViewOptions

其它

macOS 默认只允许运行通过苹果应用商店下载的软件。macOS 如果想安装第三方应用需要到 Preference/系统偏好设置 > Security & Privacy/安全性与隐私 > General/通用 中开启,Allow apps downloaded from: 🔘 Anywhere

✦ Disable System Integrity Protection (SIP)

需要重启 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 ⌘ F ⌘ N ⌘ Tab ⌘ Space ⌘ W ⌘ Q

系统通用

  • 睡眠: ⇧ ⌘ ⏏
  • 锁屏: ⌃ ⌘ Q
  • 进入全屏模式:⌃ ⌘ F
  • Character Viewer(弹出 emojis): ⌃ ⌘ Space
  • Show all windows of the front app: ⌃ ↓
  • Show all windows: ⌃ ↑
  • Forward delete: Fn del
  • Paste without formatting: ⇧ ⌘ V
  • Screenshot: ⇧ ⌘ 4 Space(选择区域)⇧ ⌘ 3(整个屏幕)
  • 保存文件: ⌘ S
  • 另存文件: ⇧ ⌘ S
  • 在应用程序之间切换:⌘ tab
  • 在单个应用程序的多个窗口之间切换:⌘ ~
  • 新建窗口:⌘ N
  • 隐藏窗口:⌘ H
  • 最小化窗口:⌘ M
  • 关闭当前窗口:⌘ W
  • 退出: ⌘ Q
  • 强行退出: ⌥ ⌘ Esc

Finder

  • 打开 home folder: ⇧ ⌘ H
  • 打开 desktop folder: ⇧ ⌘ D
  • 打开文件、上级目录、下级目录:⌘O ⌘↑ ⌘↓
  • 回到前一个目录: ⌘ [
  • 转到下一个目录: ⌘ ]
  • 隐藏文件的开关: ⇧ ⌘ .

  MacOS 快捷键完整列表

软件

网上都有盗版或破解,需要花点时间找。Apple 的 MacOS 源自 Unix,但其自带系统软件难用,一二十年毫无大进步,和微软的 Windows 的用户体验差距不小,好在是第三方挺给力。

必备工具

  • Amphetamine:防止进入睡眠状态,定时休眠 🆓

  • App Cleaner & Unistaller:应用深度清理卸载

  • BetterZipArchive Utility:压缩/解压缩

  • CleanMyMacLemon:垃圾清理,软件卸载,系统优化

  • 键指如飞/FlyKey:列出了当前活动应用所有支持的键盘快捷组合键 🆓

  • Hidden Bar:菜单栏图标隐藏 🆓

  • Paralles Desktop:Windows 虚拟机,配合 PD Runner(原来挂在 Github 上,后来被毙了,可到 Gitee 上下载),解锁最新试用版 Paralles

  • Paragon NTFS for Mac:不用虚拟机,直接挂 NTFS,比较稳定了

  • Rectangle:开源版的 spectacle,和 Moom 类似管理窗口大小和定位,拖拽窗口即能定位,超级好用,配上快捷键 🆓

  • iTerms2zshoh-my-zshFig:命令行相关,见下

一些体会:

  • List of useful Quick Look plugins for developers
  • USB 外挂大硬盘必备,读写 NTFS,发现 Paragon NTFS 或者 Tuexra NTF,移动文件过程中会出现文件莫名其妙的失踪 🥶,只好采取虚机这个迂回的办法。
  • Paralles:Windows 对 MBP 的 Retina 的支持不好,DPI 不可以超过 185%,参见 Resize Search Box and Address Box Win7
  • Paralles:在 Windows 里删除 shared folder 里的文件(非挂靠在 Windows 的硬盘),不会进入 Windows 回收站
  • Moom 的快捷窗口操作(Rectangle取代):
    Moom
  • Aflred/Raycast 据说是个神器,spotlight+,可迅速定制各种任务的快捷方式,。
  • Apple 会把 TNT 的证书删除,碰到软件打不开的问题,需要自行重新签发证书:
> codesign --force --deep --sign - /Applications/xxx.app

常用软件

  • Adobe AcrobatPDF 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 订阅
  • ScreenshotShottr:截图 🆓
  • OmiScreenFlow:录屏 👍🏻
  • Sketch:矢量画图

其它常用软件:

  • Chrome 及一堆插件(Goolge 同步)
  • Windows Office for Mac
  • 各种网盘软件:百度网盘、Dropbox、Google Drive 等
  • 微信 Wechat,Whatsapp,Telegram,Twitter,Discord,Slack,Zoom,Teams 等一众社交软件

开发工具

JetBrain 的全家桶 IntelliJ Pycharm WebStorm Goland 是我十多年来开发 Java 和其它语种的主力 IDE,各种文本编辑基本已归置 VS Code 和 强大的 Notepad++(Windows only)。Windows 上经常画图的工具是Visio,慢慢转到 Excalidrawdraw.io

vi/vim 我是半吊子,非常有空才打算深入。

VPN

🆓 七款 VPN 比较:

VPN 名称注册可连接国家限速用量使用设备广告P2P
AtlasVPN不要 ✅3🈶️无限制 ✅1🈚️ ✅是 ✅
Hotspot Shield不要 ✅1🈶️500MB/天1🈶️是 ✅
PrivadoVPN12🈚️ ✅10GB/月1🈚️ ✅是 ✅
ProtonVPN3🈶️无限制 ✅1🈚️ ✅
Speedify不要 ✅几乎全部  ✅🈚️ ✅1GB/月1🈚️ ✅
TunnelBear23🈚️ ✅500MB/天1🈚️ ✅是 ✅
Windscribe10🈶️10GB/月1🈚️ ✅

myu## 命令行

💡 命令行各种配置的保留,参考之前的文章:  如何保存 dotfiles

命令行的东西比较杂,主要有那么几大件:

  • homebrew:软件安装管理必备神器,相当于 Linux 上的 yum,装完后一通 brew cask install 和 brew install
  • zsh oh-my-zsh(OMZ):OMZ 是个 zsh 的集成者
  • iTerm2:比 Mac 自带的 terminal 强,颜色(Dracula),字体(Hack),窗体,快键唤出等等,自行安装和设置。另外可以配合 tmux 多窗口管理器使用。
  • Fig:命令行自动补全神器 👍🏻

brew

brew 的备份和迁移

brew 可以通过 brew bundle 进行备份,然后一键在另外一台机器上恢复:

cat Brewfile

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,但更快
ag
  • asciinema:可以录制 terminal
asciinema
  • bat:增加语法高亮,取代 cat
bat
  • broot:取代 tree
broot
  • choosecutawk 功能结合
choose
  • curlie: 简化 curl
curlie
  • dust:Rust 开发,取代 du
dust
  • exa:取代 ls
exa
  • fd:更快,更友好,取代 find
fd
  • fig:命令行自动补全
fig
fzf
  • gping:取代 ping
gping
  • hyperfine:benchmark/测速工具
hyperfine
  • htop:取代 top 类似的还有gtop

  • httpie:命令行 http,类似 wgetcurl

httpie
  • jq:json 文件浏览、格式化、支持高亮,有一点学习曲线,看参考 jq cheetsheet 和来自文档的一些使用技巧
jq
  • procs:显示 PID 和 TCP 端口,取代 ps,用 Rust 开发
procs
  • psgrep:取代 ps aux | grep

  • pstree:Linux 上移植过来,树型方式显示进程

  • ripgrep:更快,更友好,和 grep 类似但遵循 gitignore

ripgrep
  • sd:取代 sed
sd
  • shellcheck:shell script 语法检查
shellcheck
  • thefuck:神器
thefuck
  • tldr:取代 man
tldr
  • xh:与 httpie 简洁界面类似,但速度更快
xh
  • xz:压缩工具

参考:Julia Evans 的 A list of new(ish) command line tools

zsh

plugins

zsh 的插件很多,自行选择 awesome-zsh-plugins

  • zsh-syntax-highlighting
zsh-syntaxhighlight
  • zsh-autosuggestions
zsh-autosuggestion
  • zsh-history-substring-search
zsh-substring

命令行提示符

OMZ Theme 自带的和那个 Powerlevel10K 太眼花缭乱,这个简约 spaceship

alias

参考如下:

### =======
### Alias
### =======

# brew
alias b="brew"
alias bdump="rm ~/Brewfile; brew bundle dump; dotadd ~/Brewfile; dotcmt; dotpush"
alias bsearch="brew search"
alias binfo="brew info"
alias bls="brew list --versions"
alias bold="brew outdated"
alias badd="brew install"
alias bdel="brew uninstall"
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 bstart="brew services start"
alias bstop="brew services stop"
alias bsvc="brew services list"
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"

# ANTLR 4
# export CLASSPATH=".:/usr/local/lib/antlr-4.10.1-complete.jar:$CLASSPATH"
# alias antlr="java -jar /usr/local/lib/antlr-4.10.1-complete.jar"
# alias grun="java org.antlr.v4.gui.TestRig"

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 nsearch="npm search"
alias ninfo="npm info"alias nls="npm list"
alias nlsg="npm list -g"
alias nold="npm outdated"
alias noldg="npm outdated -g"
alias ninit="npm init"
alias nadd="npm install"
alias naddg="npm install -g"
alias ndev="npm install --save-dev"
alias ndel="npm uninstall"
alias ndelg="npm uninstall -g"
alias nclean="npm cache clean --force"
alias nupdg='echo "updating node global modules ......"; npm cache verify; npm outdated -g; npm update -g; npm fund; npm audit fix --force'
alias nrun="npm run"
alias nsvr="npm run server"
alias nbuild="npm run lint && npm run build"
alias ntest="npm run test"
alias depgraph='depcruise --max-depth 2 --exclude "^node_modules" --output-type dot src | dot -T svg > dependencyGraph.svg'

# pnpm
export PNPM_HOME="/Users/fastzhong/Library/pnpm"
alias pn="pnpm"
alias pni="pnpm install"
alias pnadd="pnpm add"
alias pnaddg="pnpm add -g"
alias pndep="pnpm add -D"
alias pndel="pnpm remove"
alias pndelg="pnpm remove -g"
alias pnclean="pnpm store prune"
alias pnupd="pnpm update"
alias pnupdg="pnpm update -g"
alias pnrun="pnpm run"

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
###
export PYENV_HOME=$HOME/.pyenv
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
# Created by `pipx` on 2021-09-30 10:42:22
export PATH="$PATH:/Users/fastzhong/.local/bin"
alias peadd="pyenv install"
alias pedel="pyenv unstall"
alias py="python"
alias pypath='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/*'

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 gtag="git log --no-walk --tags --pretty=format:' %C(yellow)%h %Cgreen%d %Cred%ad %Creset%s' --date=local"

# branch sorted by last modified
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 glocal="git branch -vv --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 gco="git checkout"
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"

# 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"
alias gco="git checkout"

# git commit
alias gcmt="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"

# 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'

# 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 gupd="git pull --prune && git submodule update --init --recursive"
alias grebdev="git checkout develop && git pull && git checkout - && git rebase -i develop"
alias gcont="git rebase --continue"
# deletes all local branches that have already been merged to develop
alias gdelmgd="git checkout develop && git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d"

# git submodule
f_git_sub_add() {
    git submodule add "$1" "$2"
    git submodule init
    git submodule update --remove --recursive
}
alias gmodadd="f_git_sub_add"

f_git_sub_del() {
    git submodule deinit -f "$1"
    rm -rf .git/modules/"$1"
    git rm -f "$1"
}
alias gmoddel="f_git_sub_del"

# caution: delete untracked files
alias gclean="git clean -nxfd"
alias gcleanx="git clean -xfd && git gc --auto"

# 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="kubectl"
alias kcfg="nocorrect k config view"
alias kctx="kubectx"
alias kns="kubens"
alias ktell="kubectl explain"
alias kns="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"
# krew
alias krewadd="kubectl krew install"
# stern
alias sternapp="kubectl stern"
alias sterncontainer="kubectl stern --container"
alias sternauth="kubectl stern -t --since 30m auth"
export do="-o yaml --dry-run=client"

# Istio

alias c="bat"
alias cdls='f_cdls(){cd "$1" && exa -lh}; f_cdls'
alias cddown="cd ~/Downloads; exa -lh"
alias cdwork="cd ~/workspace; exa -lh"
alias cdoss="cd ~/workspace/oss; exa -lh"
alias cdmy="cd /Volumes/MySpace2021/; exa -lh"
alias cdmywork="cd /Volumes/MySpace2021/workspace; exa -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="exa -1"
alias ls="exa -lh"
alias lt="exa -T"
alias ll="exa -lah"
alias llt='f_llt(){exa -lah --git --git-ignore --tree --level="$1"}; f_llt'

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 routes="netstat -nr"
alias ports="netstat -n -a -p tcp | grep LISTEN"

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"
alias codem251="code /Volumes/MySpace2021/workspace/SUSS/MTH251/github/mth251.code-workspace"
alias codem252="code /Volumes/MySpace2021/workspace/SUSS/MTH251/github/mth252.code-workspace"
alias codefaang="code /Volumes/MySpace2021/workspace/faang/faang.code-workspace"

iTerm2

iTerm2 -> Install Shell Integration

selection

iterm2-selection

自带快捷键

FunctionShortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
Splitting
Split Window Vertically (same profile) + D
Split Window Horizontally (same profile) + Shift + D (mnemonic: shift is a wide horizontal key)
Moving
Move a pane with the mouse + Alt + Shift and then drag the pane from anywhere
Fullscreen
Fullscreen+ Enter
Maximize a pane + Shift + Enter (use with fullscreen to temp fullscreen a pane!)
Resize PaneCtrl + + Arrow (given you haven’t mapped this to something else)
Less Often Used By Me
Go to Split Pane by Order of Use + ] , + [
Split Window Horizontally (new profile)Option + + H
Split Window Vertically (new profile)Option + + V
Previous Tab+ Left Arrow (I usually move by tab number)
Next Tab+ Right Arrow
Go to Window + Option + Number

shell 常用的快捷键

自定义快捷键:

iterm2-keymap1 iterm2-keymap2
快捷键命令发送字符
⌥ ←左移一个单词Escape Sequenceb
⌥ →右移一个单词Escape Sequencef
⌘ ←移至行首Hex Codes0x01
⌘ →移至行尾Hex Codes0x05
⌥ Del删除至词首Hex Codes0x17
⌘ Del删除整行Hex Codes0x15
⌘ 𝐳undoHex Codes0x1f

iTerm2 技巧

  • iTerm2 允许我们快速查看剪贴板内容 只需使用 ⌘ ⇧ h 可以呼出粘贴历史
  • 在 iTerm2 中,双击选中,三击选中整行,四击智能选中(智能规则可配置)
  • 按住 ⌘ 键:可以拖拽选中的字符串
    • 点击 url:调用默认浏览器访问该网址;
    • 点击文件:调用默认程序打开文件;
    • 点击文件夹:在 finder 中打开该文件夹;
    • 同时按住 ⌥ 键,可以以矩形选中,类似于 vim 中的 ⌃ v 操作
  • 将文本内容复制到剪切板
  • 在 Finder 中打开当前目录

session 恢复

  1. system preferences - general:
    session1

  2. iTerm2 - settings - General:
    session1

session1

vi 快捷键 & 技巧

bindkey -v 加到 .zshrc 里,命令行就可以用 vi 的快捷键(bindkey -e 则是 emacs)。

💡 注意如果使用 vi 快捷键,其它常规的就会失效。

快速移动

FunctionShortcut
Move to the start of lineCtrl + A or Home
Move to the end of lineCtrl + E or End
Move forward a wordOption + F
Move backward a wordOption + B
Set Mark + M
Jump to Mark + J
Moving by word on a line (this is a shell thing but passes through fine)Ctrl + Left/Right Arrow
Cursor Jump with Mouse (shell and vim - might depend on config)Option + Left Click

Copy & Paste

FunctionShortcut
Enter Copy ModeShift + + C
Enter Character Selection Mode in Copy ModeCtrl + V
Move cursor in Copy ModeHJKL vim motions or arrow keys
Copy text in Copy ModeCtrl + K

命令行历史

FunctionShortcut
Search as you typeCtrl + R and type the search term; Repeat Ctrl + R to loop through result
Search the last remembered search termCtrl + R twice
End the search at current history entryCtrl + Y
Cancel the search and restore original lineCtrl + G

常用

FunctionShortcutUse
Delete to start of lineCtrl + UUse this to start over typing without hitting Ctrl-C
Delete to end of lineCtrl + KUse this with command history to repeat commands and changing one thing at the end!
Repeat last commandUp ArrowCycle and browse your history with up and down. Ctrl-R is faster if you know the string you are looking for.
Move back and forth on a lineArrow KeysThis takes you off the home row but it’s easy to remember
Move back and forth on a line by words + Arrow KeysFast way to jump to a word to correct a typo or “run again” with minor changes
Delete previous word (in shell)Ctrl + WIt’s faster to delete by words. Especially when your last command was wrong by a single typo or something.
Clear screenCtrl + LThis 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.

巨量资源

🛒 购买 MacRumors Buyer’s Guide :非常实用,购买苹果产品前必看 💎💎💎

🛒 命令行

🛒 软件介绍

🛒 软件下载

工具

  上一篇:Hugo

  下一篇:我理解的架构 & 架构师(兼谈微服务)

comments powered by Disqus