fix(oh-my-zsh): fix remote oh-my-zsh issue (#496)

* fix(oh-my-zsh): fix remote oh-my-zsh issue
This commit is contained in:
SteveLauC
2023-07-18 13:59:55 +08:00
committed by GitHub
parent 42188af02b
commit 9415d7c61f
2 changed files with 31 additions and 0 deletions

View File

@@ -165,6 +165,28 @@ pub fn run_zim(ctx: &ExecutionContext) -> Result<()> {
pub fn run_oh_my_zsh(ctx: &ExecutionContext) -> Result<()> {
require("zsh")?;
// When updating `oh-my-zsh` on a remote machine through topgrade, the
// following processes will be created:
//
// SSH -> ZSH -> ZSH ($SHELL) -> topgrade -> ZSH
//
// The first ZSH process, won't source zshrc (as it is a login shell),
// and thus it won't have the ZSH environment variable, as a result, the
// 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 && echo $ZSH", zshrc_path.display()).as_str(),
])
.output_checked_utf8()?;
env::set_var("ZSH", output.stdout.trim());
}
let oh_my_zsh = env::var("ZSH")
.map(PathBuf::from)
// default to `~/.oh-my-zsh`