Skip to content

Commit

Permalink
new: Don't newly create .bash_profile (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
tats-u authored Nov 12, 2024
1 parent c00259e commit 3de0db5
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions crates/shell/src/shells/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ impl Bash {
}
}

fn has_bash_profile(home_dir: &Path) -> bool {
home_dir.join(".bash_profile").exists()
}

fn profile_for_bash(home_dir: &Path) -> PathBuf {
// https://github.com/moonrepo/starbase/issues/99
// Ubuntu doesn't have .bash_profile. It uses .profile instead.
// If .bash_profile is newly created, .profile will be no longer loaded.
if has_bash_profile(home_dir) {
home_dir.join(".bash_profile")
} else {
home_dir.join(".profile")
}
}

// https://www.baeldung.com/linux/bashrc-vs-bash-profile-vs-profile
impl Shell for Bash {
fn format(&self, statement: Statement<'_>) -> String {
Expand Down Expand Up @@ -70,19 +85,24 @@ fi
}

fn get_config_path(&self, home_dir: &Path) -> PathBuf {
home_dir.join(".bash_profile")
profile_for_bash(home_dir)
}

fn get_env_path(&self, home_dir: &Path) -> PathBuf {
home_dir.join(".bash_profile")
profile_for_bash(home_dir)
}

fn get_profile_paths(&self, home_dir: &Path) -> Vec<PathBuf> {
vec![
home_dir.join(".bash_profile"),
home_dir.join(".bashrc"),
home_dir.join(".profile"),
]
if has_bash_profile(home_dir) {
vec![
home_dir.join(".bash_profile"),
home_dir.join(".bashrc"),
home_dir.join(".profile"),
]
} else {
// Default .profile calls .bashrc in Ubuntu
vec![home_dir.join(".profile"), home_dir.join(".bashrc")]
}
}

/// Quotes a string according to Bash shell quoting rules.
Expand Down

0 comments on commit 3de0db5

Please sign in to comment.