From 27ec4a2d389771eaabacdaeb69bded8ed9019f22 Mon Sep 17 00:00:00 2001 From: sususu98 Date: Fri, 12 Dec 2025 14:03:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=AE=80=E5=8C=96=20shell=20?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=EF=BC=8C=E4=BB=85=E6=94=AF=E6=8C=81=20bash?= =?UTF-8?q?=20=E5=92=8C=20zsh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 fish shell 支持 - 其他 shell 显示不支持错误并退出 - 简化 write_env_to_shell 函数 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- ClaudeCode/setup-claude-code.sh | 15 +++++---------- codex/setup-codex.sh | 15 +++++---------- setup.sh | 4 +++- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/ClaudeCode/setup-claude-code.sh b/ClaudeCode/setup-claude-code.sh index 7ac23cf..a4492d3 100644 --- a/ClaudeCode/setup-claude-code.sh +++ b/ClaudeCode/setup-claude-code.sh @@ -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" diff --git a/codex/setup-codex.sh b/codex/setup-codex.sh index f586b26..895c581 100644 --- a/codex/setup-codex.sh +++ b/codex/setup-codex.sh @@ -38,10 +38,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 } @@ -62,18 +62,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" diff --git a/setup.sh b/setup.sh index 8a3ca5e..f0b9bc5 100755 --- a/setup.sh +++ b/setup.sh @@ -33,7 +33,9 @@ get_shell_rc() { echo "$HOME/.bash_profile" fi else - echo "$HOME/.profile" + error "不支持当前 shell: ${SHELL##*/}" + error "仅支持 bash 和 zsh" + exit 1 fi }