Fish Shell配置踩坑经验

Posted by Forgus on 2026-03-16

问题描述

执行 chsh -s $(which fish) 将默认 shell 改为 fish 后,无法找到 opencode 命令原先在 bash 中输入 fish 可以识别 opencode 命令

原因分析

~/.config/fish/config.fish 中使用了以下配置:

1
2
3
if status is-interactive
set -gx PATH $PATH ~/.opencode/bin
end

这导致 PATH 设置只在交互式 shell 中生效,登录 shell(非交互式)无法加载。

解决方案

使用 fish_add_path 命令在 conf.d 目录创建独立配置文件:

文件: ~/.config/fish/conf.d/opencode.path.fish

1
2
# 添加 opencode 到 PATH
fish_add_path ~/.opencode/bin

验证方法

1
2
su - root -c "which opencode"
# 输出: /root/.opencode/bin/opencode

相关文档