refactor: 简化 shell 检测,仅支持 bash 和 zsh
- 移除 fish shell 支持 - 其他 shell 显示不支持错误并退出 - 简化 write_env_to_shell 函数 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -29,10 +29,10 @@ get_shell_rc() {
|
||||
else
|
||||
echo "$HOME/.bash_profile"
|
||||
fi
|
||||
elif [ "${SHELL##*/}" = "fish" ]; then
|
||||
echo "$HOME/.config/fish/config.fish"
|
||||
else
|
||||
echo "$HOME/.profile"
|
||||
print_error "不支持当前 shell: ${SHELL##*/}"
|
||||
print_error "仅支持 bash 和 zsh"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -53,18 +53,13 @@ write_env_to_shell() {
|
||||
fi
|
||||
|
||||
# 转义特殊字符(使用单引号包裹更安全)
|
||||
local export_line
|
||||
if [ "${SHELL##*/}" = "fish" ]; then
|
||||
export_line="set -Ux $var_name '$var_value'"
|
||||
else
|
||||
export_line="export $var_name='$var_value'"
|
||||
fi
|
||||
local export_line="export $var_name='$var_value'"
|
||||
|
||||
# 删除旧的同名变量行,添加新行
|
||||
local tmp_file
|
||||
tmp_file=$(mktemp)
|
||||
if [ -s "$rc_file" ]; then
|
||||
grep -v "^export $var_name=" "$rc_file" | grep -v "^set -Ux $var_name " >"$tmp_file" 2>/dev/null || true
|
||||
grep -v "^export $var_name=" "$rc_file" >"$tmp_file" 2>/dev/null || true
|
||||
fi
|
||||
echo "$export_line" >>"$tmp_file"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user