From bf72d7bb5ac95df4a088f213ee6b7fbd946679e7 Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Mon, 22 Jan 2024 09:18:27 +0800 Subject: [PATCH] fix: oh-my-zsh step issue #646 (#647) --- src/steps/zsh.rs | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/steps/zsh.rs b/src/steps/zsh.rs index 3b5abf99..9279d198 100644 --- a/src/steps/zsh.rs +++ b/src/steps/zsh.rs @@ -179,25 +179,15 @@ pub fn run_oh_my_zsh(ctx: &ExecutionContext) -> Result<()> { // children processes won't get it either, so we source the zshrc and set // the ZSH variable for topgrade here. if ctx.under_ssh() { - let zshrc_path = zshrc().require()?; - let output = Command::new("zsh") - .args([ - "-c", - // ` > /dev/null` is used in case the user's zshrc will have some stdout output. - format!("source {} > /dev/null && export -p", zshrc_path.display()).as_str(), - ]) - .output_checked_utf8()?; - - let stdout = output.stdout; - - let prefix = "export ZSH="; - for line in stdout.lines() { - if line.contains(prefix) { - let zsh_env = line.trim_start_matches(prefix); - debug!("Oh-my-zsh: under SSH, setting ZSH={}", zsh_env); - env::set_var("ZSH", zsh_env); - break; - } + let res_env_zsh = Command::new("zsh") + .args(["-ic", "print -rn -- ${ZSH:?}"]) + .output_checked_utf8(); + + // this command will fail if `ZSH` is not set + if let Ok(output) = res_env_zsh { + let env_zsh = output.stdout; + debug!("Oh-my-zsh: under SSH, setting ZSH={}", env_zsh); + env::set_var("ZSH", env_zsh); } }