From 7fa38c593ee4f8e78c3bd66928a3b38f7356d2ef Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Sun, 29 Oct 2023 18:05:20 +0800 Subject: [PATCH] fix: omz remote execution if ZSH is not present (#592) --- src/steps/zsh.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/steps/zsh.rs b/src/steps/zsh.rs index 8cba9ef6..3660b0ea 100644 --- a/src/steps/zsh.rs +++ b/src/steps/zsh.rs @@ -181,16 +181,20 @@ pub fn run_oh_my_zsh(ctx: &ExecutionContext) -> Result<()> { .args([ "-c", // ` > /dev/null` is used in case the user's zshrc will have some stdout output. - format!( - "source {} > /dev/null && export -p | grep ZSH > /dev/null && echo $ZSH", - zshrc_path.display() - ) - .as_str(), + format!("source {} > /dev/null && export -p", zshrc_path.display()).as_str(), ]) .output_checked_utf8()?; - let zsh_env = output.stdout.trim(); - if !zsh_env.is_empty() { - env::set_var("ZSH", zsh_env); + + 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; + } } }