简单分享一下终端配置

2026-04-11 11:421阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐
问题描述:

最近将原本的 Iterm2 + Oh My Zsh 更换为 Ghostty + zinit 配置终端,在使用的过程中优化了一下体验,给大家分享出来作为参考:

  1. 终端配置:

Ghostty的配置是以文件形式存储在$HOME/Library/Application Support/com.mitchellh.ghostty/文件下的,修改或者更新配置通过快捷键 cmd + ,使用默认程序打开配置文件,全部的配置选项在: Option Reference - Configuration 可以查看
贴出我的配置:

# --- Typography --- font-family = "Maple Mono NF CN" font-size = 18 adjust-cell-height = 2 # --- Theme and Colors --- theme = Catppuccin Mocha # --- Window and Appearance --- background-opacity = 0.95 background-blur-radius = 30 macos-titlebar-style = transparent window-padding-x = 10 window-padding-y = 8 window-save-state = always window-theme = auto # --- Cursor --- cursor-style = bar cursor-style-blink = true cursor-opacity = 0.8 # --- Mouse --- mouse-hide-while-typing = true copy-on-select = clipboard # --- Quick Terminal --- keybind = global:ctrl+grave_accent=toggle_quick_terminal quick-terminal-position = center quick-terminal-screen = mouse quick-terminal-autohide = true quick-terminal-animation-duration = 0.15 # --- Security --- clipboard-paste-protection = true clipboard-paste-bracketed-safe = true # --- Shell Integration --- shell-integration = zsh # --- Claude 专属优化 --- # initial-command = /opt/homebrew/bin/claude initial-window = true quit-after-last-window-closed = true notify-on-command-finish = always # --- Performance --- scrollback-limit = 25000000 # --- 基础分屏(左右添加屏幕)--- keybind = cmd+d=new_split:right keybind = cmd+shift+enter=toggle_split_zoom keybind = cmd+shift+f=toggle_split_zoom

  1. zinit

zinit是一个zsh的插件管理器,可以使用 bash -c "$(curl --fail --show-error --silent --location https://raw.githubusercontent.com/zdharma-continuum/zinit/HEAD/scripts/install.sh)" 一键安装。

在这里贴出我常用的插件:

语法高亮: zinit light zdharma-continuum/fast-syntax-highlighting
自动建议: zinit light zsh-users/zsh-autosuggestions
补全: zinit light zsh-users/zsh-completions

3.优化 —— Claude自定义函数

为了避免所有内容全都堆在 ⁠.zshrc 中,我把自定义逻辑单独放在一个目录里:
image1292×392 81.4 KB

其中 claude.sh 是针对claude配置切换的函数,一般来说,在使用多个公益站情况下,我们会创建多个配置文件,像这样:
image1634×1402 413 KB
那我们切换的时候就可以:claude --settings ~/.claude/settings.codex.json

但是这样命令就太长了,我们可以通过 claude-cfg [name] -c
image3242×1072 378 KB
后面也可以加对应的参数等等,如果不需要加参数,仅简单的新对话启动也可以使用 ccfg列出所有的配置进行选择,这个功能依赖 fzf :
image1250×468 70.3 KB

在此留下对应的文件 ~/.shell/claude.sh

# ============================================================ # Claude Code 配置 # ============================================================ claude-cfg() { claude --settings ~/.claude/settings."$1".json "${@:2}" } _claude-cfg() { _values 'configurations' $(ls ~/.claude/settings.*.json 2>/dev/null | sed 's/.*settings\.\(.*\)\.json/\1/') } compdef _claude-cfg claude-cfg ccfg() { local selected cfg file name url selected=$( for file in ~/.claude/settings.*.json; do [[ -f "$file" ]] || continue name="${file##*/}" name="${name#settings.}" name="${name%.json}" url="$(jq -r '.env.ANTHROPIC_BASE_URL // ""' "$file" 2>/dev/null)" printf '%s\t%s\n' "$name" "$url" done | sort | while IFS=$'\t' read -r name url; do printf '%-20s\t%s\n' "$name" "$url" done | fzf --height=10 --reverse --prompt="Config: " ) [[ -n "$selected" ]] || return cfg="${selected%%[[:space:]]*}" claude-cfg "$cfg" }

  1. 优化 —— 两个小功能

第一个 proxy/unproxy/proxy-status 用来给终端快速设置代理,放在~/.shell/proxy.sh
image784×660 75.2 KB

proxy() { local port=${1:-7890} export https_proxy=http://127.0.0.1:$port \ http_proxy=http://127.0.0.1:$port \ all_proxy=http://127.0.0.1:$port echo "✓ Proxy set to port $port" } unproxy() { unset https_proxy http_proxy all_proxy echo "✓ Proxy unset" } proxy-status() { echo "http_proxy: ${http_proxy:-未设置}" echo "https_proxy: ${https_proxy:-未设置}" echo "all_proxy: ${all_proxy:-未设置}" }

第二个,ssh选择器,在ssh配置文件中,设置了多个机器的情况下:

~ > cat .ssh/config 20:33:36 # Added by OrbStack: 'orb' SSH host for Linux machines # This only works if it's at the top of ssh_config (before any Host blocks). # This won't be added again if you remove it. Include ~/.orbstack/ssh/config Host * SetEnv TERM=xterm-256color IdentityFile ~/.ssh/id_rsa_web ServerAliveInterval 60 Host gpu HostName *** Port 6666 User cd Host 2 HostName **** Port 6666 User ab

可以通过 cssh 列出所有的配置选择连接,这个功能依赖 fzf :

image854×502 31.5 KB

文件是 ~/.shell/cssh.sh

cssh() { local host host=$( awk ' BEGIN { current_host = "" current_hostname = "" } /^[[:space:]]*Host[[:space:]]+/ { if (current_host != "" && current_host != "*") { printf "%s\t%s\n", current_host, current_hostname } current_host = $2 current_hostname = "" next } /^[[:space:]]*HostName[[:space:]]+/ { current_hostname = $2 next } END { if (current_host != "" && current_host != "*") { printf "%s\t%s\n", current_host, current_hostname } } ' ~/.ssh/config | sort | column -t -s $'\t' | fzf --height=10 --reverse --prompt="SSH: " | awk '{print $1}' ) [[ -n "$host" ]] && ssh "$host" }

最后在 ~/.zshrc 加载 ~/.shell/ 下定义的所有函数:

# 加载自定义函数 for file in ~/.shell/*.sh; do [ -f "$file" ] && source "$file" done 网友解答:


--【壹】--:

总是想换掉,最终都是懒得折腾而放弃


--【贰】--:

学习一下


--【叁】--:

感谢大佬了


--【肆】--:

我现在用的iTerm2+fish,设置代理还是直接搞了两个alias


--【伍】--:

原来终端还可以这么用的么?我只是打开,用,关闭就完了

标签:纯水
问题描述:

最近将原本的 Iterm2 + Oh My Zsh 更换为 Ghostty + zinit 配置终端,在使用的过程中优化了一下体验,给大家分享出来作为参考:

  1. 终端配置:

Ghostty的配置是以文件形式存储在$HOME/Library/Application Support/com.mitchellh.ghostty/文件下的,修改或者更新配置通过快捷键 cmd + ,使用默认程序打开配置文件,全部的配置选项在: Option Reference - Configuration 可以查看
贴出我的配置:

# --- Typography --- font-family = "Maple Mono NF CN" font-size = 18 adjust-cell-height = 2 # --- Theme and Colors --- theme = Catppuccin Mocha # --- Window and Appearance --- background-opacity = 0.95 background-blur-radius = 30 macos-titlebar-style = transparent window-padding-x = 10 window-padding-y = 8 window-save-state = always window-theme = auto # --- Cursor --- cursor-style = bar cursor-style-blink = true cursor-opacity = 0.8 # --- Mouse --- mouse-hide-while-typing = true copy-on-select = clipboard # --- Quick Terminal --- keybind = global:ctrl+grave_accent=toggle_quick_terminal quick-terminal-position = center quick-terminal-screen = mouse quick-terminal-autohide = true quick-terminal-animation-duration = 0.15 # --- Security --- clipboard-paste-protection = true clipboard-paste-bracketed-safe = true # --- Shell Integration --- shell-integration = zsh # --- Claude 专属优化 --- # initial-command = /opt/homebrew/bin/claude initial-window = true quit-after-last-window-closed = true notify-on-command-finish = always # --- Performance --- scrollback-limit = 25000000 # --- 基础分屏(左右添加屏幕)--- keybind = cmd+d=new_split:right keybind = cmd+shift+enter=toggle_split_zoom keybind = cmd+shift+f=toggle_split_zoom

  1. zinit

zinit是一个zsh的插件管理器,可以使用 bash -c "$(curl --fail --show-error --silent --location https://raw.githubusercontent.com/zdharma-continuum/zinit/HEAD/scripts/install.sh)" 一键安装。

在这里贴出我常用的插件:

语法高亮: zinit light zdharma-continuum/fast-syntax-highlighting
自动建议: zinit light zsh-users/zsh-autosuggestions
补全: zinit light zsh-users/zsh-completions

3.优化 —— Claude自定义函数

为了避免所有内容全都堆在 ⁠.zshrc 中,我把自定义逻辑单独放在一个目录里:
image1292×392 81.4 KB

其中 claude.sh 是针对claude配置切换的函数,一般来说,在使用多个公益站情况下,我们会创建多个配置文件,像这样:
image1634×1402 413 KB
那我们切换的时候就可以:claude --settings ~/.claude/settings.codex.json

但是这样命令就太长了,我们可以通过 claude-cfg [name] -c
image3242×1072 378 KB
后面也可以加对应的参数等等,如果不需要加参数,仅简单的新对话启动也可以使用 ccfg列出所有的配置进行选择,这个功能依赖 fzf :
image1250×468 70.3 KB

在此留下对应的文件 ~/.shell/claude.sh

# ============================================================ # Claude Code 配置 # ============================================================ claude-cfg() { claude --settings ~/.claude/settings."$1".json "${@:2}" } _claude-cfg() { _values 'configurations' $(ls ~/.claude/settings.*.json 2>/dev/null | sed 's/.*settings\.\(.*\)\.json/\1/') } compdef _claude-cfg claude-cfg ccfg() { local selected cfg file name url selected=$( for file in ~/.claude/settings.*.json; do [[ -f "$file" ]] || continue name="${file##*/}" name="${name#settings.}" name="${name%.json}" url="$(jq -r '.env.ANTHROPIC_BASE_URL // ""' "$file" 2>/dev/null)" printf '%s\t%s\n' "$name" "$url" done | sort | while IFS=$'\t' read -r name url; do printf '%-20s\t%s\n' "$name" "$url" done | fzf --height=10 --reverse --prompt="Config: " ) [[ -n "$selected" ]] || return cfg="${selected%%[[:space:]]*}" claude-cfg "$cfg" }

  1. 优化 —— 两个小功能

第一个 proxy/unproxy/proxy-status 用来给终端快速设置代理,放在~/.shell/proxy.sh
image784×660 75.2 KB

proxy() { local port=${1:-7890} export https_proxy=http://127.0.0.1:$port \ http_proxy=http://127.0.0.1:$port \ all_proxy=http://127.0.0.1:$port echo "✓ Proxy set to port $port" } unproxy() { unset https_proxy http_proxy all_proxy echo "✓ Proxy unset" } proxy-status() { echo "http_proxy: ${http_proxy:-未设置}" echo "https_proxy: ${https_proxy:-未设置}" echo "all_proxy: ${all_proxy:-未设置}" }

第二个,ssh选择器,在ssh配置文件中,设置了多个机器的情况下:

~ > cat .ssh/config 20:33:36 # Added by OrbStack: 'orb' SSH host for Linux machines # This only works if it's at the top of ssh_config (before any Host blocks). # This won't be added again if you remove it. Include ~/.orbstack/ssh/config Host * SetEnv TERM=xterm-256color IdentityFile ~/.ssh/id_rsa_web ServerAliveInterval 60 Host gpu HostName *** Port 6666 User cd Host 2 HostName **** Port 6666 User ab

可以通过 cssh 列出所有的配置选择连接,这个功能依赖 fzf :

image854×502 31.5 KB

文件是 ~/.shell/cssh.sh

cssh() { local host host=$( awk ' BEGIN { current_host = "" current_hostname = "" } /^[[:space:]]*Host[[:space:]]+/ { if (current_host != "" && current_host != "*") { printf "%s\t%s\n", current_host, current_hostname } current_host = $2 current_hostname = "" next } /^[[:space:]]*HostName[[:space:]]+/ { current_hostname = $2 next } END { if (current_host != "" && current_host != "*") { printf "%s\t%s\n", current_host, current_hostname } } ' ~/.ssh/config | sort | column -t -s $'\t' | fzf --height=10 --reverse --prompt="SSH: " | awk '{print $1}' ) [[ -n "$host" ]] && ssh "$host" }

最后在 ~/.zshrc 加载 ~/.shell/ 下定义的所有函数:

# 加载自定义函数 for file in ~/.shell/*.sh; do [ -f "$file" ] && source "$file" done 网友解答:


--【壹】--:

总是想换掉,最终都是懒得折腾而放弃


--【贰】--:

学习一下


--【叁】--:

感谢大佬了


--【肆】--:

我现在用的iTerm2+fish,设置代理还是直接搞了两个alias


--【伍】--:

原来终端还可以这么用的么?我只是打开,用,关闭就完了

标签:纯水