Skip to content

Commit

Permalink
fix: oh-my-zsh step issue #646 (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC authored Jan 22, 2024
1 parent dadffb1 commit bf72d7b
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions src/steps/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit bf72d7b

Please sign in to comment.