Skip to main content

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

·7499 字·15 分钟
工具 & 生产效率
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),而且可以通过 Logi 的软件进行定制:

Mac 上的好鼠标太少,此前的用过两个雷神的 DeathAdder,基本寿命就是两年,手感,响应准确度等均弱于 MX Master3

以上两个东西性价比极好,体验超级丝滑,网评可以看一波,至今我非常满意

 电脑座椅绝对值得投入,有钱直接 aeron 不用考虑:

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 jpg
$ 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 常用快捷键 #

  MacOS 快捷键完整列表

 宇宙通用
⌘ , ⌘ A ⌘ C ⌘ V ⌘ X ⌘ Z ⌘ R ⌘ F ⌘ N ⌘ ⇥ ⌘ ␣ ⌘ W ⌘ Q
 系统通用
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:防止进入睡眠状态,定时休眠
360 压缩大师Archive Utility:压缩/解压缩
CleanMyMacLemon:垃圾清理,软件卸载,系统优化
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
  • 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 AcrobatPDF Expert:PDF 老东家,还是比 PDF Expert 好用,只是软件太臃肿
Beyond Compare:文件/文件夹对比神器
Boom3D:音效加强
CleanShot X:截屏
Dash:编程文档
Downie:各种视频下载,支持优酷、腾讯视频、bilibili、土豆、爱奇艺、网易、搜狐、微博以及国外的 Youtube 等等
Find My:跟踪 Apple 设备,防止遗失
Folx Pro:各种 p2p 下载
GoodNote:手写体笔记
Klack:模拟机械键盘的敲击声,超酷
magnetw:开源种子搜索神器,可惜已经关闭 😭
Movist Pro:Mac 上最好的 movie 播放器
PopClip:Copy/Paste 剪贴板工具
Reeder:rss 订阅
ScreenshotShottr :截图
OmiClevershot XScreenFlow剪映:录屏,视频剪辑

其它常用软件:

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

Chrome 插件 #

普通插件介绍
AI 课代表视频总结, 字幕列表, GPT-4
AdGuard AdBlocker - Chrome Web Store广告去除
Awesome ChatGPT Screenshot & Screen Recorder 截图和屏幕录制
Better History
ChatGPT for Google
ChatGPT for StackOverflow
ChatGPT Glarity利用 ChatGPT4 生成摘要,支持 Youtube 视频和谷歌
Clear Cache
Clutter Free禁重复 tab
Control Panel for Twitter支持多个 Twitter 账号切换
Copy Link Text
Copy Title and Url as Markdown Style
Grammarly语法检查
Modern for Hacker News - Chrome Web Store
I don’t care about cookies
Immersive Translate: Web Page&PDF Translation - Chrome Web Store 网页对照翻译
SimpleUndoCloseUndo closed tabs
Toby for Chrome 默认标签页,收集和快速打开常用网站
YouTube™ dual subtitles 双语字幕,字幕下载
Youtube 中文配音
开发类插件
Enhanced GitHub - Chrome Web Store
JSON Formatter - Chrome Web Store
Lighthouse - Chrome Web Store
LiveReload - Chrome Web Store
OctoLinker - Google 搜索
React Developer Tools - Chrome Web Store
Sourcegraph - Chrome Web Store
Web Developer Checklist - Chrome Web Store
Vue.js devtools - Chrome Web Store

开发工具 #

JetBrain 的全家桶 IntelliJPycharmWebStormGolandDataGrip 是我十多年来开发 Java 和其它语种的主力 IDE,各种文本编辑基本已归置 VS Code。以前 Windows 上经常画图的工具是 Visio,现在转到 draw.ioExcalidraw eraser.io。Git 命令行基本够用,偶尔看看 Gitkraken 神器 Modules-Learn/技术/Gitkraken 最新版 v9.x 破解教程.md at master · wanZzz6/Modules-Learn

VS Code 功夫

Intellj 功夫

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🈚️  

命令行 #

命令行各种配置的保留,参考之前的文章:

如何保存 dotfiles
·313 字·1 分钟
工具 & 生产效率

dotfiles - 你肯定知道这个东西是什么,不然就不要往下看了

命令行大件
iTerm2比 Mac 自带的 terminal 强,颜色 aura-theme-soft,字体 Hack Nerd Font,命令行提示 starship,窗体,快键唤出等等,自行安装和设置。另外可以配合 tmux 多窗口管理器使用
homebrewMac 软件安装管理必备神器,相当于 Linux 上的 yum,装完后一通 brew install
zsh增强型 bash, oh-my-zsh OMZ 是个 zsh 的集成者
Fig命令行自动补全神器

iTerm2 #

iTerm2 自带快捷键 #

FunctionShortcut
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

iTerm2 自定义快捷键 #

如何自定义快捷键:
iterm2-keymap-1 iterm2-keymap-2

自定义快捷键命令发送字符
⌥ ←左移一个单词Escape Sequenceb
⌥ →右移一个单词Escape Sequencef
⌘ →移至行首Hex Codes0x01
⌘ ←移至行尾Hex Codes0x05
⌥ ⌫删除至词首Hex Codes0x17
⌘ ⌫删除整行Hex Codes0x15
⌘ ZundoHex Codes0x1f

命令行常用快捷键 #

FunctionShortcutUse
Delete to start of line⌃ UUse this to start over typing without hitting ⌃ C
Delete to end of line⌃ KUse 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)⌃ WIt’s faster to delete by words. Especially when your last command was wrong by a single typo or something.
Clear screen⌃ 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.
区别 ⌘ K ⌃ L

一个区别是 ⌘ K 清除回滚缓冲区以及屏幕。 ⌃ L 仅清除屏幕,有效地将屏幕上的内容“向上”移动到回滚缓冲区中。

另一个区别是 ⌃ L 是由终端内运行的进程执行的。例如,bash 将清除屏幕并重新绘制提示符,包括其中任何未完成的命令。其他程序可能继续刷新而不是先清除屏幕。另一方面, ⌘ K 由终端本身执行,无论窗口中运行什么,因此它可能会隐藏程序的输出。

采纳 vi 快捷键 #

  注意如果使用 vi 快捷键,上述命令行快捷键就会失效。

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

vi 快捷键

selection 设置 #

iterm2-selection.

session 恢复 #

1. system preferences - general:iterm2-session-1
2. iTerm2 - settings - General:iterm2-session-2
3. iterm2-session-3

命令行提示 starship #

Starship: Cross-Shell Prompt,我挺喜欢 Tokyo-night:

iTerm2 其它技巧 #

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

iTerms 备份和恢复 #

iTerms2 的设置可以保存到文件里,然后从备份文件里恢复:

tmux #

brew 和 命令行工具 #

brew 的备份和恢复 #

brew 可以通过 brew bundle 进行备份 Brewfile,然后一键在另外一台机器上恢复,Brewfile 和通常的 brew 略有不同:

命令行Brewfile
brew install [formulaName]brew “[forumlaName]”
brew cask install [caskName]cask “[caskName]”
mas install [identifier]mas “[bundleIdentifier]”, id: [identifier]

恢复/安装:

$ brew bundle

增强型命令行工具 #

 A list of new(ish) command line tools
ag 搜索工具,类似 ack
asciinema 可以录制 terminal
bat 增加语法高亮,取代 cat
broot 取代 tree
choose 结合 cutawk 功能
curlie 简化 curl
dust 取代 du
eza 取代 find
fd 取代 find
fig 超强命令行自动补全,神器
fzf 文件模糊搜索
gping 取代 ping
hyperfine benchmark/测速工具
htop 取代 top
httpie 命令行 http
jq json 文件浏览、格式化、支持高亮
procs 显示 PID 和 TCP 端口,取代 ps
psgrep 树型方式显示进程
ripgrepgrep 类似但遵循 gitignore
sd 取代 sed
shellcheck shell script 语法检查
thefuck
tldr 取代 man
xh 与 httpie 简洁界面类似,但速度更快
xz 压缩工具
增强型命令行工具

  • ag 搜索工具,类似 ack,但更快

    ag

  • asciinema 可以录制 terminal

    asciinema

  • bat 增加语法高亮,取代 cat

    bat

  • broot 取代 tree

    broot

  • choose 结合 cutawk 功能

    choose

  • curlie 简化 curl

    curlie

  • dust Rust 开发,取代 du

    dust

  • eza 取代 ls

    eza

  • fd 更快,更友好,取代 find

    fd

  • fig 命令行自动补全,神器

    fig

  • fzf 文件模糊搜索,参考 Vim universe. fzf - command line fuzzy finder

    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 压缩工具

zsh #

plugins #

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

zsh-syntax-highlightingzsh-syntaxhighlight
zsh-history-substring-searchzsh-substring

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 21)
export PATH=${JAVA_HOME}/bin:$PATH
export JAVA_OPTS=
alias java="java"
alias javac="javac"
alias javaj="java -jar"
# shows the statck trace of a specified java process id
alias jps="jps -l"

# maven
export M2_HOME=/usr/local/Cellar/g/3.9.6/libexec
export PATH=${M2_HOME}/bin:$PATH
export MAVEN_HOME=$M2_HOME
export M2_OPTS=
alias mclean="mvnd clean"
alias minstall='mvnd clean install -Dmaven.test.skip=true'
alias mtest='mvnd test'
alias mpkg='mvnd package'

# gradle
export GRADLE_HOME=/usr/local/Cellar/gradle/8.5/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="gupd; ./gradlew build"
alias grjar="./gradlew bootJar"
alias grrun="./gradlew bootRun"
alias grdep="./gradlew -q dependencies"

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 -g"
alias nls0="npm list -g --depth=0"
alias nls1="npm list -g --depth=1"
alias nls2="npm list -g --depth=2"
alias nls3="npm list -g --depth=3"
alias nold="npm outdated -g"
alias nsearch="npm search -g"
alias ninfo="npm info"
alias nadd="npm install -g"
alias ndel="npm uninstall -g"
alias nupd='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 ndev="npm run dev"
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/fastzhong/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/zhonglun/go
export GOROOT=/usr/local/opt/go/libexec
export PATH=${GOROOT}/bin:${GOPATH}/bin:$PATH
export GO111MODULE=on
export CGO_ENABLE=0
export GOOS=darwin
export GOARCH=amd64

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 pyadd="pyenv install"
alias pydel="pyenv uninstall"
alias pywhich="pyenv which"
# ~/.pyenv/version
alias pyglobal="pyenv global"
# .python-version
alias pylocal="pyenv local"
# 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"
alias ptenv="poetry env info"
# 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 PATH=${OPENRESTY_HOME}/bin:$PATH
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'

### DevOps
###
# 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"
alias gren="git branch -m"
alias gdel="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 'update everything'"
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
# change last commit message
alias gamd="git commit --amend"
# Caution: discard uncommitted changes even if already added to staging area and workign directory (hard) and remove untrack
alias gundo="git reset --hard; git clean -df; if [ -d '.git/rebase-apply' ] || [ -d '.git/rebase-merge' ]; then git rebase --abort; fi;"
# Caution: go back to the previous commit and remove changes in staging area and working directory (hard)
alias glast="git reset --hard HEAD~1"
alias grevert="git revert"
alias grestore="git restore --source="

# 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'
alias greflog="git reflog"
alias gnew="git log main..HEAD"
alias gmissing="git log HEAD..main"

# 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 grebasec="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 gclean="git clean -nxfd"
alias gcleanx="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 d='docker'
alias dclean='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 dprune='docker system prune -af'
alias dbuild="DOCKER_BUILDKIT=1 docker build ."
alias dexe="docker exec --it"
alias dps="docker ps -a"
# docker compose
alias dcbuild="docker compose build"
alias dcstart="docker compose start"
alias dcstop="docker compose stop"
alias dcup="docker compose up -d"
alias dcdown="docker compose down"
alias dclog="docker compose logs"


# Kubernetes
# general
alias k="kubecolor"
alias kc="kubectl"
alias kctx="kubectx"
alias kcfg="nocorrect k config view"
alias ktree="k tree"
alias knp="k np-viewer"
alias ktell="k explain"
alias kdbg="kubectl debug"

# namespace
alias kn="kubens"
alias knnew="k create namespace"
alias knsys="k -n kube-system"

# create resource
alias kcreate="k create -f"
alias kapply="k apply -f"

# delete resource
alias kdel="k delete"
alias kdnode="k delete nodes"
alias kdpod="k delete pods"
alias kdpoda="k delete pods --all-namespaces"
alias kdsvc="k delete services"
alias kddpl="k delete deployments"

# get resource
alias kgnode="k get nodes -o wide"
alias kgpod="k get pods -o wide"
alias kgpoda="k get pods -o wide --all-namespaces"
alias kgsvc="k get services -o wide"
alias kgdpl="k get deployments -o wide"

# describe resource
alias kdesc="k describe"
alias knode="kubectl describe node"
alias kdpl="kubectl describe deployment"
alias kpod="kubectl describe pod"
alias ksvc="kubectl describe svc"

alias ksh='k run -it --image bash --restart Never --rm shell'
alias krbac="k rbac-tool analysis --cluster-context"
alias krole="k rolesum"
alias kwho="k rbac-tools who-can"
alias kcan="k rakkess"
alias kcanas="k rakkess --as"

# krew
export PATH=${KREW_ROOT:-$HOME/.krew}/bin:$PATH
alias krewupd="k krew update && k krew upgrade"
alias krewadd="k krew install"
alias krewdel="k krew unistall"

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

topN() {
    sort $1 | uniq -c | sort -nr | head -n $2
}

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

vi 快捷键 #

快速移动 #

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

FunctionShortcut
Enter Copy Mode⇧ ⌘ C
Enter Character Selection Mode in Copy Mode⌃ V
Move cursor in Copy ModeH J K L vim motions or arrow keys
Copy text in Copy Mode⌃ K

命令行历史 #

FunctionShortcut
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

巨量资源 #

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

🛒 命令行

🛒 软件介绍

🛒 软件下载