现代终端工作流配置方案

目标

这套配置面向 infra / platform engineer 的日常工作流:

  • Terminal: Ghostty
  • Shell: zsh
  • Prompt: starship
  • Multiplexer: tmux
  • CLI 美化: eza / bat / fd / ripgrep
  • K8s: k9s / kubectx / kubens / stern / helm
  • Git TUI: lazygit
  • 辅助工具: fzf / zoxide / git-delta / jq / yq / bottom / dust

启动链路:

Ghostty -> zsh -> starship prompt -> tmux session -> lazygit / k9s / kubectl / eza / bat / rg / fd

安装命令

brew install ghostty zsh starship tmux eza bat fd ripgrep k9s lazygit
brew install jq yq fzf zoxide git-delta kubectx helm stern bottom dust
brew install --cask font-jetbrains-mono-nerd-font

当前机器已安装并验证:

starship 1.25.1
eza 0.23.4
bat 0.26.1
fd 10.4.2
ripgrep 15.1.0
k9s 0.50.18
lazygit 0.61.1

配置文件位置

~/.zshrc
~/.config/starship.toml
~/.tmux.conf
~/.config/ghostty/config
~/.config/bat/config

zsh 配置

文件:~/.zshrc

eval "$(/opt/homebrew/bin/brew shellenv)"
 
export PATH="/opt/homebrew/opt/openjdk@21/bin:$PATH"
export PATH="/Users/justinx/Library/Python/3.9/bin:$PATH"
export PATH="$HOME/bin:$PATH"
 
# >>> Codex modern CLI workflow >>>
export EDITOR="${EDITOR:-vim}"
export PAGER="${PAGER:-less}"
export LESS="-R"
 
if [[ -o interactive ]]; then
  autoload -Uz compinit
  compinit
 
  if [[ "${TERM:-}" != "dumb" ]]; then
    eval "$(starship init zsh)"
  fi
 
  if [[ "${TERM:-}" != "dumb" ]] && [[ -t 0 && -t 1 ]] && command -v fzf >/dev/null 2>&1; then
    source <(fzf --zsh)
  fi
fi
 
if command -v zoxide >/dev/null 2>&1; then
  eval "$(zoxide init zsh)"
fi
 
alias ls="eza --icons --group-directories-first"
alias ll="eza -lah --icons --group-directories-first"
alias la="eza -a --icons --group-directories-first"
alias tree="eza --tree --icons"
 
alias cat="bat"
alias grep="rg"
alias find="fd"
 
alias lg="lazygit"
alias k="kubectl"
alias kctx="kubectl config current-context"
alias kx="kubectx"
alias kn="kubens"
 
alias ta="tmux attach -t"
alias tls="tmux ls"
alias tn="tmux new -s"
 
alias du="dust"
alias top="btm"
alias diff="delta"
# <<< Codex modern CLI workflow <<<

说明:

  • brew shellenv 放在前面,保证 Homebrew 工具可用。
  • ~/bin 仍然保留较高优先级,因此当前 helm 仍优先使用 /Users/justinx/bin/helm
  • starshipfzf 只在交互式终端中初始化,避免脚本或 Codex 非真实 TTY 场景出现噪音。
  • TERM=dumb 时跳过 prompt/fzf 初始化,提升兼容性。

Starship 配置

文件:~/.config/starship.toml

format = """
$username$hostname$directory$git_branch$git_status$kubernetes$docker_context$terraform$nodejs$python$golang$java$cmd_duration
$character
"""
 
add_newline = true
 
[character]
success_symbol = "[❯](bold green)"
error_symbol = "[❯](bold red)"
 
[directory]
style = "bold cyan"
truncation_length = 3
truncate_to_repo = true
 
[git_branch]
symbol = "git:"
style = "bold purple"
 
[git_status]
style = "bold red"
 
[kubernetes]
disabled = false
symbol = "k8s:"
format = '[$symbol$context( \($namespace\))]($style) '
style = "bold blue"
 
[docker_context]
symbol = "docker:"
style = "blue"
 
[terraform]
symbol = "tf:"
style = "bold 105"
 
[nodejs]
symbol = "node:"
format = "[$symbol($version)]($style) "
 
[python]
symbol = "py:"
format = "[$symbol($version)]($style) "
 
[golang]
symbol = "go:"
format = "[$symbol($version)]($style) "
 
[java]
symbol = "java:"
format = "[$symbol($version)]($style) "
 
[cmd_duration]
min_time = 1000
format = "took [$duration](bold yellow) "

说明:

  • 默认展示当前目录、Git 分支和状态、Kubernetes context、Docker context、Terraform、常见语言版本、命令耗时。
  • Kubernetes context 会直接显示在 prompt 中,进入生产集群前更容易警觉。

如不想在 prompt 中显示 Kubernetes context:

[kubernetes]
disabled = true

tmux 配置

文件:~/.tmux.conf

set -g mouse on
set -g history-limit 50000
 
set -g base-index 1
setw -g pane-base-index 1
 
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",xterm-256color:Tc"
 
unbind C-b
set -g prefix C-a
bind C-a send-prefix
 
bind r source-file ~/.tmux.conf \; display-message "tmux config reloaded"
 
bind | split-window -h
bind - split-window -v
 
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
 
setw -g mode-keys vi

说明:

  • prefix 从默认 C-b 改为 C-a
  • | 横向分 pane,- 纵向分 pane。
  • h/j/k/l 在 pane 间移动。
  • prefix r 重新加载 tmux 配置。

Ghostty 配置

文件:~/.config/ghostty/config

term = xterm-256color
 
font-family = JetBrainsMono Nerd Font
font-size = 14
 
theme = Catppuccin Mocha
 
window-padding-x = 10
window-padding-y = 8
 
cursor-style = block
cursor-style-blink = false
 
macos-option-as-alt = true

说明:

  • 使用 JetBrainsMono Nerd Font,保证 starship/eza 图标正常显示。
  • 主题使用当前 Ghostty 内置可识别的 Catppuccin Mocha
  • macos-option-as-alt = true 方便终端快捷键和 readline 操作。

bat 配置

文件:~/.config/bat/config

--theme="TwoDark"
--style="numbers,changes,header"
--paging=auto

验证命令

TERM=xterm-256color zsh -ic 'echo ZSH_OK'
starship explain >/tmp/starship-explain.txt && echo STARSHIP_OK
tmux -f ~/.tmux.conf start-server \; source-file ~/.tmux.conf \; list-keys >/tmp/tmux-keys.txt && echo TMUX_OK
ghostty +validate-config --config-file=$HOME/.config/ghostty/config

工具链检查:

command -v starship eza bat fd rg k9s lazygit tmux fzf zoxide delta kubectx kubens helm stern btm dust

注意事项

  • 当前工作区 /Users/justinx/Documents/vibecoding 不是单一 git 仓库,具体项目仍需进入子目录后再判断 git 状态和构建工具。
  • 当前 Obsidian vault 地址:/Users/justinx/Library/Mobile Documents/iCloud~md~obsidian/Documents/obsidian-main
  • Homebrew 安装过 helm,但当前 shell 仍优先使用 /Users/justinx/bin/helm
  • 如果 Ghostty 主题名报错,使用 ghostty +list-themes 查看当前版本支持的主题名。