优化Zsh插件安装流程和命令执行器

- 重构Zsh插件安装逻辑,将硬编码URL拆分为源和目标路径
- 修改RealTimeCommandExecutor,增加实时命令执行日志输出
- 优化SingleLineCommandExecutor日志信息,改进命令日志可读性
- 简化插件安装命令,支持国内外镜像源的插件克隆
This commit is contained in:
zeaslity
2025-03-11 16:14:28 +08:00
parent 34b5f80704
commit 8e4444a7cc
2 changed files with 27 additions and 21 deletions

View File

@@ -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]})
}
}
// 下载插件

View File

@@ -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()