You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iTerm2下fish shell如何设置Solarized Dark默认背景色并永久生效

问题描述

具体而言,我希望在iTerm2运行的fish shell环境中,将默认背景色设置为 Solarized Dark。

目前我每次启动fish shell时,都必须使用快捷键CMD + I手动更改背景,操作示意如下:
通过CMD + I手动设置背景

是否存在可行的配置方式,让上述设置能够永久保存生效?

我当前的fish_variables文件内容如下:

# This file contains fish universal variable definitions.
# VERSION: 3.0
SETUVAR __fish_initialized:3400
SETUVAR fish_color_autosuggestion:586e75
SETUVAR fish_color_cancel:\x2d\x2dreverse
SETUVAR fish_color_command:93a1a1
SETUVAR fish_color_comment:586e75
SETUVAR fish_color_cwd:green
SETUVAR fish_color_cwd_root:red
SETUVAR fish_color_end:268bd2
SETUVAR fish_color_error:dc322f
SETUVAR fish_color_escape:00a6b2
SETUVAR fish_color_history_current:\x2d\x2dbold
SETUVAR fish_color_host:normal
SETUVAR fish_color_host_remote:\x1d
SETUVAR fish_color_keyword:\x1d
SETUVAR fish_color_match:\x2d\x2dbackground\x3dbrblue
SETUVAR fish_color_normal:normal
SETUVAR fish_color_operator:00a6b2
SETUVAR fish_color_option:\x1d
SETUVAR fish_color_param:839496
SETUVAR fish_color_quote:657b83
SETUVAR fish_color_redirection:6c71c4
SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dblack
SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack
SETUVAR fish_color_status:red
SETUVAR fish_color_user:brgreen
SETUVAR fish_color_valid_path:\x2d\x2dunderline
SETUVAR fish_key_bindings:fish_default_key_bindings
SETUVAR fish_pager_color_background:\x1d
SETUVAR fish_pager_color_completion:B3A06D
SETUVAR fish_pager_color_description:B3A06D
SETUVAR fish_pager_color_prefix:cyan\x1e\x2d\x2dunderline
SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan
SETUVAR fish_pager_color_secondary_background:\x1d
SETUVAR fish_pager_color_secondary_completion:\x1d
SETUVAR fish_pager_color_secondary_description:\x1d
SETUVAR fish_pager_color_secondary_prefix:\x1d
SETUVAR fish_pager_color_selected_background:\x2d\x2dbackground\x3dbrblack
SETUVAR fish_pager_color_selected_completion:\x1d
SETUVAR fish_pager_color_selected_description:\x1d
SETUVAR fish_pager_color_selected_prefix:\x1d
解决方案

背景色是iTerm2终端模拟器自身的配置项,不归fish shell管理。你现在修改的fish_variables只控制fish命令行的文字高亮配色,无法作用于终端背景,所以每次重启都会重置,按下面步骤操作就能永久生效:

  • 按快捷键CMD + ,直接打开iTerm2全局设置,不要用CMD + I打开单窗口临时面板,该面板的改动默认不会持久化存储。
  • 顶部切换到Profiles标签,左侧列表选中你日常使用的默认配置(名称通常为Default,条目左侧带对勾标识的就是默认启动项)。
  • 右侧配置区切换到Colors页,找到页面右下角的Color Presets...下拉按钮,点开后直接在预设列表中选择Solarized Dark,选择后当前窗口会实时预览效果。
  • 效果符合预期直接关闭设置窗口即可,iTerm2会自动保存配置,后续所有新开的终端窗口,无论运行fish、zsh还是bash,都会默认使用Solarized Dark背景。

注意:如果你坚持用CMD + I打开的临时检查器面板修改配置,改完一定要点击面板底部的Use as Defaults按钮,否则设置仅对当前窗口生效,终端关闭后就会失效。

你当前fish_variables里配置的文字高亮规则本身已经适配Solarized Dark配色,不需要额外修改fish侧的任何配置,改完iTerm2的profile设置就能直接得到完整的Solarized Dark显示效果。
如果有特殊需求,只想在启动fish时自动切换到Solarized Dark背景、其他shell场景保留iTerm2默认背景,也可以往~/.config/fish/config.fish中添加iTerm2控制转义序列实现,但这类场景非常少见,优先修改iTerm2默认profile的方案稳定性最高,不会出现兼容问题。

内容的提问来源于stack exchange,提问作者Olivia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.27 11:36:20