系統設定#
程序塭自動隱藏加速
# 設定啟動塭動畫時間設定為 0.5 秒
defaults write com.apple.dock autohide-time-modifier -float 0.5 && killall Dock
# 設定啟動塭響應時間最短
defaults write com.apple.dock autohide-delay -int 0 && killall Dock
# 恢復啟動塭預設動畫時間
defaults delete com.apple.dock autohide-time-modifier && killall Dock
# 恢復預設啟動塭響應時間
defaults delete com.apple.Dock autohide-delay && killall Dock
啟動台自定義行和列
# 設定列數
defaults write com.apple.dock springboard-columns -int 7
# 設定行數
defaults write com.apple.dock springboard-rows -int 6
# 重啟 Dock 生效
killall Dock
# 恢復預設的列數和行數
defaults write com.apple.dock springboard-rows Default
defaults write com.apple.dock springboard-columns Default
# 重啟 Dock 生效
killall Dock
常用軟體安裝#
命令行工具#
統一採用 Homebrew 對系統軟體包進行管理,安裝命令行工具時,優先考慮 Homebrew 提供的軟體包。
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
差生文具多:
Prefer | Description | Replace |
---|---|---|
eza | A modern, maintained replacement for ls. | ls |
zoxide | A smarter cd command, supports all major shells. | cd |
htop | An interactive process viewer. | top |
ripgrep | ripgrep recursively searches directories for a regex pattern while respecting your gitignore. | grep |
ncdu | Ncdu (NCurses Disk Usage) is a disk usage analyzer with an ncurses interface. | du |
bat | A cat(1) clone with wings. | cat |
fd | A simple, fast and user-friendly alternative to 'find'. | find |
procs | A modern replacement for ps written in Rust. | ps |
fzf | A general-purpose command-line fuzzy finder written in Go. | find |
fzf-tab | Replace zsh's default completion selection menu with fzf. | find |
tokei | A program that displays statistics about your code. | cloc |
tldr | Collaborative cheatsheets for console commands. | man |
thefuck | Magnificent app which corrects your previous console command. | - |
lazygit | A simple terminal UI for git commands. | git |
lazydocker | A simple terminal UI for both docker and docker-compose. | docker |
fastfetch | Like neofetch, but much faster because written mostly in C. | neofetch |
delta | A syntax-highlighting pager for git, diff, and grep output. | diff |
終端利器 Fzf#
在日常的 shell 環境中,可以透過 Fzf + Ripgrep + Bat + Vim 來提升效率,方便地管理文件及其內容。
-
文件查詢:
使用 pf (preview file) 別名快速預覽和選擇文件。調用 Fzf 進行互動式模糊查找,並使用 Bat 在右側窗口實現語法高亮,預覽選中文件的前 500 行內容。可以透過 Shift+Up 和 Shift+Down 翻頁,提高效率。
alias pf='fzf --preview='\''bat --color=always --style=header,grid --line-range \ :500 {}'\'' --bind shift-up:preview-page-up,shift-down:preview-page-down'
如下圖所示:
-
內容查詢:
使用 rfv (ripgrep-fzf-vim) 函數進行全文內容搜索並在 Vim 中打開結果。搜索結果將實時展示在 Fzf 窗口中,並透過 Bat 預覽文件的相關內容。綁定按鍵 Enter 鍵和 Ctrl+O 鍵以實現在 Vim 中打開搜索結果,便於進行進一步的編輯。
rfv() ( RELOAD='reload:rg --column --color=always --smart-case {q} || :' OPENER='if [[ $FZF_SELECT_COUNT -eq 0 ]]; then vim {1} +{2} # No selection. Open the current line in Vim. else vim +cw -q {+f} # Build quickfix list for the selected items. fi' fzf --disabled --ansi --multi \ --bind "start:$RELOAD" --bind "change:$RELOAD" \ --bind "enter:become:$OPENER" \ --bind "ctrl-o:execute:$OPENER" \ --delimiter : \ --preview 'bat --style=header,grid --color=always --line-range :500 --highlight-line {2} {1} \ --preview-window '~4,+{2}+4/3,<80(up)' \ --query "$*" )
如下圖所示:
可以將以上內容添加至 ~/.zshrc
文件中,從而構建一個更加高效的命令行 Workflow。
Zsh 配置#
常用的 Oh My Zsh 對我來說略顯臃腫,因此我選擇使用 zinit 來管理插件。
至此,~/.zshrc
可以分為幾個模塊,分別定義不同的功能配置:
zinit 相關#
在安裝 zinit 的過程中,它會自動的接管 ~/.zshrc
,並向其中添加其相關配置如下:
### Added by Zinit's installer
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
print -P "%F{33} %F{34}Installation successful.%f%b" || \
print -P "%F{160} The clone has failed.%f%b"
fi
source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
# Load a few important annexes, without Turbo
# (this is currently required for annexes)
zinit light-mode for \
zdharma-continuum/zinit-annex-as-monitor \
zdharma-continuum/zinit-annex-bin-gem-node \
zdharma-continuum/zinit-annex-patch-dl \
zdharma-continuum/zinit-annex-rust
### End of Zinit's installer chunk
加載環境變量#
# Load Environment Variables
export PATH="/Users/lkw123/Library/Python/3.9/bin:$HOME/.cargo/bin:$PATH"
export BAT_THEME="Monokai Extended Origin"
export STARSHIP_CONFIG="/Users/lkw123/.config/starship/starship.toml"
export GPG_TTY=$(tty)
三個基礎插件#
- zdharma/fast-syntax-highlighting: 語法高亮,與
zsh-syntax-highlighting
功能幾乎一致,個人使用習慣更偏向於 f-sy-h。 - zsh-users/zsh-autosuggestions: 自動補全,根據歷史命令自動補全。
- zsh-users/zsh-completions: 補全插件,提供了常用命令的補全。
# Add in zsh plugins
zinit light zdharma-continuum/fast-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-autosuggestions
# Load completions
autoload -Uz compinit && compinit
# Completion styling
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no
引入 fzf-tab#
值得注意的一點是,根據 fzf-tab 的 README 中的 compatibility-with-other-plugins 所言,需要將 fzf-tab 的引入放在配置文件的最後部分,以避免和 zsh-completions 插件產生衝突。
# fzf-tab init and styling
zinit light Aloxaf/fzf-tab
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza --icons -1 --color=always $realpath'
zstyle ':fzf-tab:complete:__zoxide_z:*' fzf-preview 'eza --icons -1 --color=always $realpath'
zstyle ':fzf-tab:complete:z:*' fzf-preview 'eza --icons -1 --color=always $realpath'
透過以上的配置,可以實現在 cd 目錄時,配合 fzf 的功能快速預覽目標目錄的文件結構:
定義別名#
# Aliases
alias ls="eza"
alias ll="eza --time-style=default --icons --git -l"
alias la="eza --time-style=long-iso --icons --group --git --binary -la"
alias tree="eza --tree --icons"
alias cls="clear"
alias cat="bat"
alias v="nvim"
歷史記錄#
# History
HISTSIZE=5000
HISTFILE=~/.zsh_history
SAVEHIST=$HISTSIZE
HISTDUP=erase
setopt appendhistory
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups
Shell 集成#
- starship:基於 Rust 的跨平台的 Shell 提示符,具有輕量、迅速、客製化的特點,選用 Tokyo Night Preset;
- thefuck:用於快速更改輸錯的命令,實際使用中比較雞肋,使用場景沒有預想的多;
- zoxide:用於快速跳轉常用的工作目錄;
- fnm:Node.js 版本管理工具。
# Shell integrations
eval "$(starship init zsh)"
eval "$(thefuck --alias)"
eval "$(fzf --zsh)"
eval "$(zoxide init zsh)"
eval "$(fnm env --use-on-cd)"
最後,簡單測試一下 Zsh 的啟動時間:
-
采用直觀的比較 Naive 的方式直接觀測 zsh 的啟動速度:
❯ for i in $(seq 10); do /usr/bin/time zsh -lic exit done 0.16 real 0.10 user 0.04 sys 0.13 real 0.09 user 0.03 sys 0.13 real 0.09 user 0.03 sys 0.13 real 0.09 user 0.03 sys 0.13 real 0.09 user 0.03 sys 0.14 real 0.10 user 0.03 sys 0.14 real 0.09 user 0.03 sys 0.13 real 0.09 user 0.03 sys 0.13 real 0.09 user 0.03 sys 0.13 real 0.09 user 0.03 sys
-
借助 zsh-bench 更完善的對 zsh 的啟動時間進行基準測試:
❯ ./zsh-bench ==> benchmarking login shell of user lkw123 ... creates_tty=0 has_compsys=1 has_syntax_highlighting=1 has_autosuggestions=1 has_git_prompt=1 first_prompt_lag_ms=199.405 first_command_lag_ms=202.526 command_lag_ms=59.470 input_lag_ms=4.480 exit_time_ms=136.965
確實挺不錯的 :)
開發工具#
- Warp:一個由 Rust 編寫的跨平台終端,性能優秀,同時還有 AI 加持;
- VS Code:常用的輕量級代碼編輯器,部分推薦插件如下:
- Zed Editor:採用 Rust 構建,性能強大速度快,支持 Copilot 和實時協作等,目前作為主力編輯器使用;
GUI 工具#
統一採用 Homebrew Cask 進行管理。
$ brew list
==> Formulae
...
==> Casks
1password iina plex
alacritty jellyfin sabnzbd
applite loop transmit
daisydisk lulu tuxera-ntfs
downie netnewswire typora
font-jetbrains-mono-nerd-font notion zed
font-lxgw-wenkai orbstack
handbrake pictureview
開發環境#
- Python: uv -> An extremely fast Python package installer and resolver, written in Rust
- Node: fnm -> Fast and simple Node.js version manager, built in Rust
- Java: jenv -> Java enVironment Manager
- Go: gvm -> Go Version Manager
- Rust: rustup -> The Rust toolchain installer
Tmux 配置#
感謝 B 站 UP 主帕特里柯基在視頻 和我一起配置 tmux 中分享的配置過程。我的 Tmux 配置基本是照搬過來:
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'tmux-plugins/tmux-yank'
# catppuccin theme
set -g @plugin "catppuccin/tmux"
set -g @catppuccin_flavour "mocha"
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
# non-plugin options
set -g default-terminal "tmux-256color"
set -g base-index 1
set -g pane-base-index 1
set -g renumber-windows on
set -g mouse on
# visual mode
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
# keymaps
unbind C-b
set -g prefix C-Space
MacOS 軟體一鍵更新#
準備工作#
- 安裝 brew-cask-upgrade:
brew tap buo/cask-upgrade
- 驗證
brew-cask-upgrade
是否安裝成功:brew tap | grep buo/cask-upgrade
- 安裝 mas,一個用於管理 Mac App Store 上的應用的命令行工具:
brew install mas
更新軟體#
升級所有已安裝的軟體:
brew update && brew upgrade && brew cu --all --yes --cleanup \
&& mas upgrade && brew cleanup
-
brew update
:更新 Homebrew 自身及其相關軟體源的信息,確保 Index 信息準確; -
brew upgrade
:將系統中已安裝的所有 Homebrew 軟體包升級到最新版本; -
brew cu --all --yes --cleanup
:自動升級所有可更新的 Homebrew cask 軟體包到最新版本,並在完成後清理刪除舊版本;
- -all: Include apps that auto-update in the upgrade.
- -yes: Update all outdated apps; answer yes to updating packages.
- -cleanup: Cleans up cached downloads and tracker symlinks after updating.
-
mas upgrade
: 一鍵更新從 Mac App Store 安裝的應用程序; -
brew cleanup
: 用於清理 Homebrew 安裝的軟體包時產生的臨時文件和緩存,以釋放磁碟空間。
執行結果樣例如下:
可以作為定時任務,周期性執行,以保持 Mac 上軟體為最新版本。
我的部分 dotfiles 托管於 GitHub 倉庫 synthpop123/dotfiles,僅用於備份用途。