提交 c3f5adfe 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

implement task#7667

上级 21db7cc1
......@@ -27,16 +27,20 @@
"translation": "1) 请选择您要使用的语言,中文请输入数字1。\n2) Please select the language. Input 2 for English."
},
{
"id": "add_to_path",
"translation": "Would you like to add ZenData to PATH environment variable? (y/n, default is Yes)"
"id": "add_to_path_win",
"translation": "Would you like to add zd.exe to $PATH environment variable? (y/n, default is Yes)"
},
{
"id": "add_to_path_linux",
"translation": "Would you like to add zd command to $PATH environment variable? (y/n, default is Yes)"
},
{
"id": "add_to_path_success_win",
"translation": "Success to add PATH environment variable, please reopen the command window."
"translation": "Success to add $PATH environment variable, please reopen the command window."
},
{
"id": "add_to_path_success_linux",
"translation": "Success to add PATH environment variable, please execute 'source %s' to make it effective."
"translation": "Success to add $PATH environment variable, please execute 'source %s' to make it effective."
},
{
"id": "current_config",
......
......@@ -22,16 +22,20 @@
"translation": "1) 请选择您要使用的语言,中文请输入数字1。\n2) Please select the language. Input 2 for English."
},
{
"id": "add_to_path",
"translation": "是否将ZenData加入Path环境变量,以方便在任何目录中执行?(y/n, 默认Yes)"
"id": "add_to_path_win",
"translation": "是否将zd.exe加入$Path环境变量,以方便在任何目录中执行?(y/n, 默认Yes)"
},
{
"id": "add_to_path_linux",
"translation": "是否将zd命令加入$Path环境变量,以方便在任何目录中执行?(y/n, 默认Yes)"
},
{
"id": "add_to_path_success_win",
"translation": "成功设置PATH环境变量,请重新打开命令行窗口。"
"translation": "成功加入$PATH环境变量,请重新打开命令行窗口。"
},
{
"id": "add_to_path_success_linux",
"translation": "成功设置PATH环境变量,请执行source %s使其生效。"
"translation": "成功加入$PATH环境变量,请执行source %s使其生效。"
},
{
"id": "current_config",
......
......@@ -145,7 +145,12 @@ func InputForSet() {
// set PATH environment vari
var addToPath bool
stdinUtils.InputForBool(&addToPath, true, "add_to_path")
if commonUtils.IsWin() {
stdinUtils.InputForBool(&addToPath, true, "add_to_path_win")
} else {
stdinUtils.InputForBool(&addToPath, true, "add_to_path_linux")
}
if addToPath {
AddZdToPath()
}
......@@ -159,22 +164,44 @@ func AddZdToPath() {
home := userProfile.HomeDir
if commonUtils.IsWin() {
addZdToPathWin(home)
} else {
addZdToPathLinux(home)
}
}
func addZdToPathWin(home string) {
pathVar := os.Getenv("PATH")
if strings.Contains(pathVar, vari.ExeDir) { return }
cmd := fmt.Sprintf("setx PATH \"%%PATH%%;%s\" /m", vari.ExeDir)
out, err := shellUtils.ExeShell(cmd)
if err == nil {
msg := i118Utils.I118Prt.Sprintf("add_to_path_success_win")
logUtils.PrintToWithColor(msg, color.FgRed)
} else {
path := fmt.Sprintf("%s%s%s", home, constant.PthSep, ".bash_profile")
logUtils.PrintToWithColor(
i118Utils.I118Prt.Sprintf("fail_to_exec_cmd", cmd, err.Error() + ": " + out), color.FgRed)
}
}
content := fileUtils.ReadFile(path)
if strings.Contains(content, vari.ExeDir) { return }
func addZdToPathLinux(home string) {
path := fmt.Sprintf("%s%s%s", home, constant.PthSep, ".bash_profile")
cmd := fmt.Sprintf("echo 'export PATH=$PATH:%s' >> %s", vari.ExeDir, path)
out, err := shellUtils.ExeShell(cmd)
content := fileUtils.ReadFile(path)
if strings.Contains(content, vari.ExeDir) { return }
if err == nil {
logUtils.PrintToWithColor(i118Utils.I118Prt.Sprintf("add_to_path_success_linux", path), color.FgRed)
} else {
logUtils.PrintToWithColor(
i118Utils.I118Prt.Sprintf("fail_to_exec_cmd", cmd, err.Error() + ": " + out), color.FgRed)
}
cmd := fmt.Sprintf("echo 'export PATH=$PATH:%s' >> %s", vari.ExeDir, path)
out, err := shellUtils.ExeShell(cmd)
if err == nil {
msg := i118Utils.I118Prt.Sprintf("add_to_path_success_linux", path)
logUtils.PrintToWithColor(msg, color.FgRed)
} else {
logUtils.PrintToWithColor(
i118Utils.I118Prt.Sprintf("fail_to_exec_cmd", cmd, err.Error() + ": " + out), color.FgRed)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册