Skip to content

Commit

Permalink
Simplify zsh logic to always write to .zshenv
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Jul 3, 2020
1 parent 0cb19b8 commit 664a92d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
19 changes: 6 additions & 13 deletions src/cli/self_update/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,15 @@ impl UnixShell for Zsh {
_ => utils::home_dir(),
};

// Don't bother with .zprofile/.zlogin because .zshrc will always be
// modified and always be sourced.
[".zshenv", ".zshrc"]
.iter()
.filter_map(|rc| zdotdir.as_ref().map(|dir| dir.join(rc)))
.collect()
// .zshenv is always sourced
match zdotdir.map(|dir| dir.join(".zshenv")) {
Some(zshenv) => vec![zshenv],
_ => vec![],
}
}

fn update_rcs(&self) -> Vec<PathBuf> {
// .zshenv is preferred for path mods but not all zshers prefer it,
// zsh always loads .zshrc on interactive, unlike bash's xor-logic.
// So picking one will always work for this.
// .zshenv is preferred for path mods, always write it.
self.rcfiles()
.into_iter()
.filter(|rc| rc.is_file())
.take(1)
.collect()
}
}
20 changes: 4 additions & 16 deletions tests/cli-self-upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,6 @@ fn install_adds_path_to_zshenv() {
install_adds_path_to_rc(".zshenv");
}

#[test]
#[cfg(unix)]
fn install_adds_path_to_zshrc() {
install_adds_path_to_rc(".zshrc");
}

#[test]
#[cfg(unix)]
fn install_does_not_add_path_to_bash_profile_that_doesnt_exist() {
Expand Down Expand Up @@ -379,10 +373,10 @@ fn install_errors_when_rc_file_cannot_be_updated() {

#[test]
#[cfg(unix)]
fn install_with_zsh_adds_path_to_zshrc() {
fn install_with_zsh_adds_path_to_zshenv() {
setup(&|config| {
let my_rc = "foo\nbar\nbaz";
let rc = config.homedir.join(".zshrc");
let rc = config.homedir.join(".zshenv");
raw::write_file(&rc, my_rc).unwrap();

let mut cmd = clitools::cmd(config, "rustup-init", &["-y"]);
Expand All @@ -398,14 +392,14 @@ fn install_with_zsh_adds_path_to_zshrc() {

#[test]
#[cfg(unix)]
fn install_with_zsh_adds_path_to_zdotdir_zshrc() {
fn install_with_zsh_adds_path_to_zdotdir_zshenv() {
setup(&|config| {
let zdotdir = tempfile::Builder::new()
.prefix("zdotdir")
.tempdir()
.unwrap();
let my_rc = "foo\nbar\nbaz";
let rc = zdotdir.path().join(".zshrc");
let rc = zdotdir.path().join(".zshenv");
raw::write_file(&rc, my_rc).unwrap();

let mut cmd = clitools::cmd(config, "rustup-init", &["-y"]);
Expand Down Expand Up @@ -475,12 +469,6 @@ fn uninstall_removes_path_from_zshenv() {
uninstall_removes_path_from_rc(".zshenv");
}

#[test]
#[cfg(unix)]
fn uninstall_removes_path_from_zshrc() {
uninstall_removes_path_from_rc(".zshrc");
}

#[test]
#[cfg(unix)]
fn uninstall_doesnt_touch_rc_files_that_dont_contain_cargo_home() {
Expand Down

0 comments on commit 664a92d

Please sign in to comment.