From 8e4444a7ccace3179c65b0cbd1467e2ec7c06036 Mon Sep 17 00:00:00 2001 From: zeaslity Date: Tue, 11 Mar 2025 16:14:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Zsh=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E6=B5=81=E7=A8=8B=E5=92=8C=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构Zsh插件安装逻辑,将硬编码URL拆分为源和目标路径 - 修改RealTimeCommandExecutor,增加实时命令执行日志输出 - 优化SingleLineCommandExecutor日志信息,改进命令日志可读性 - 简化插件安装命令,支持国内外镜像源的插件克隆 --- agent-wdd/cmd/Zsh.go | 40 ++++++++++++++++++++++------------------ agent-wdd/op/Excutor.go | 8 +++++--- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/agent-wdd/cmd/Zsh.go b/agent-wdd/cmd/Zsh.go index 2f1d2a7..98d37c6 100644 --- a/agent-wdd/cmd/Zsh.go +++ b/agent-wdd/cmd/Zsh.go @@ -71,18 +71,31 @@ func addZshSubcommands(cmd *cobra.Command) { ) } - op.SingleLineCommandExecutor(installZshCommand) + // 执行 oh-my-zsh 安装命令 + op.RealTimeCommandExecutor(installZshCommand) log.Info("安装zsh完成, 开始安装插件!") - pluginsHardCodeUrl := []string{ - "https://gitee.com/wangl-cc/zsh-autosuggestions.git /root/.oh-my-zsh/plugins/zsh-autosuggestions", - "https://gitee.com/xiaoqqya/zsh-syntax-highlighting.git /root/.oh-my-zsh/plugins/zsh-syntax-highlighting", + pluginsHardCodeUrl := [][]string{ + { + "https://gitee.com/wangl-cc/zsh-autosuggestions.git", + "/root/.oh-my-zsh/plugins/zsh-autosuggestions", + }, + { + "https://gitee.com/xiaoqqya/zsh-syntax-highlighting.git", + "/root/.oh-my-zsh/plugins/zsh-syntax-highlighting", + }, } - pluginsHardCodeOutsideUrl := []string{ - "https://github.com/zsh-users/zsh-autosuggestions /root/.oh-my-zsh/plugins/zsh-autosuggestions", - "https://github.com/zsh-users/zsh-syntax-highlighting.git /root/.oh-my-zsh/plugins/zsh-syntax-highlighting", + pluginsHardCodeOutsideUrl := [][]string{ + { + "https://github.com/zsh-users/zsh-autosuggestions", + "/root/.oh-my-zsh/plugins/zsh-autosuggestions", + }, + { + "https://github.com/zsh-users/zsh-syntax-highlighting.git", + "/root/.oh-my-zsh/plugins/zsh-syntax-highlighting", + }, } pluginsListUrl := []string{ @@ -91,26 +104,17 @@ func addZshSubcommands(cmd *cobra.Command) { "https://gitea.107421.xyz/zeaslity/ohmyzsh/src/branch/master/plugins/themes/themes.plugin.zsh", } - if config.ConfigCache.Agent.Network.Internet == 7 { - log.Info("使用gitea镜像安装插件!") - pluginsHardCodeUrl = append(pluginsHardCodeUrl, - "wget -c -i https://b2.107421.xyz/oh-my-zsh-plugins-list.txt -P /root/.oh-my-zsh/plugins/", - ) - - } else { - log.Info("使用github安装插件!") - } // 下载插件 if config.ConfigCache.Agent.Network.Internet == 7 { // 执行硬编码命令, 安装插件 for _, command := range pluginsHardCodeUrl { - op.SingleLineCommandExecutor([]string{"git", "clone", command}) + op.SingleLineCommandExecutor([]string{"git", "clone", command[0], command[1]}) } } else { // 执行硬编码命令, 安装插件 国外 for _, command := range pluginsHardCodeOutsideUrl { - op.SingleLineCommandExecutor([]string{"git", "clone", command}) + op.SingleLineCommandExecutor([]string{"git", "clone", command[0], command[1]}) } } // 下载插件 diff --git a/agent-wdd/op/Excutor.go b/agent-wdd/op/Excutor.go index 7e15830..e4f5266 100644 --- a/agent-wdd/op/Excutor.go +++ b/agent-wdd/op/Excutor.go @@ -18,12 +18,12 @@ import ( // []string - 合并后的标准输出和标准错误内容(按行分割) func SingleLineCommandExecutor(singleLineCommand []string) (ok bool, resultLog []string) { - log.Info("start => %v", singleLineCommand) - if len(singleLineCommand) == 0 { return false, nil } + log.Info("start => %v", strings.Join(singleLineCommand, " ")) + // 创建命令实例 cmd := exec.Command(singleLineCommand[0], singleLineCommand[1:]...) @@ -89,7 +89,7 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) (ok bool, resultLog []s if len(cmd) == 0 { return false, nil } - pipeLineCommandStr += fmt.Sprintf("%v | ", cmd) + pipeLineCommandStr += fmt.Sprintf("%s | ", strings.Join(cmd, " ")) } pipeLineCommandStr = strings.TrimSuffix(pipeLineCommandStr, " | ") @@ -181,6 +181,8 @@ func RealTimeCommandExecutor(realTimeCommand []string) (ok bool, resultLog []str return false, nil } + log.Info("start real time command => %v", strings.Join(realTimeCommand, " ")) + cmd := exec.Command(realTimeCommand[0], realTimeCommand[1:]...) stdout, err := cmd.StdoutPipe()