Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The order of Shell::get_profile_paths is not consistent among shells; unify and clarify it #108

Closed
tats-u opened this issue Nov 19, 2024 · 1 comment · Fixed by #109
Closed

Comments

@tats-u
Copy link
Contributor

tats-u commented Nov 19, 2024

In Bash, the most preferred profile (not rc) comes first:

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")
}
}

fn get_config_path(&self, home_dir: &Path) -> PathBuf {
profile_for_bash(home_dir)
}
fn get_env_path(&self, home_dir: &Path) -> PathBuf {
profile_for_bash(home_dir)
}
fn get_profile_paths(&self, home_dir: &Path) -> Vec<PathBuf> {
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")]
}
}

In elvish, the most preferred one returned by get_config_path comes first while the "legacy" one comes last:

fn get_config_path(&self, home_dir: &Path) -> PathBuf {
get_config_dir(home_dir).join("elvish").join("rc.elv")
}
fn get_env_path(&self, home_dir: &Path) -> PathBuf {
self.get_config_path(home_dir)
}
fn get_profile_paths(&self, home_dir: &Path) -> Vec<PathBuf> {
#[allow(unused_mut)]
let mut profiles = HashSet::<PathBuf>::from_iter([
get_config_dir(home_dir).join("elvish").join("rc.elv"),
home_dir.join(".config").join("elvish").join("rc.elv"),
home_dir.join(".elvish").join("rc.elv"), // Legacy
]);

In fish, the return value of get_config_path comes first in get_profile_paths like the above 2 shells:

fn get_config_path(&self, home_dir: &Path) -> PathBuf {
get_config_dir(home_dir).join("fish").join("config.fish")
}
fn get_env_path(&self, home_dir: &Path) -> PathBuf {
self.get_config_path(home_dir)
}
fn get_profile_paths(&self, home_dir: &Path) -> Vec<PathBuf> {
HashSet::<PathBuf>::from_iter([
get_config_dir(home_dir).join("fish").join("config.fish"),
home_dir.join(".config").join("fish").join("config.fish"),
])
.into_iter()
.collect()
}

However, in nushell, the order depends on the hash algorithm of HashSet:

fn get_config_path(&self, home_dir: &Path) -> PathBuf {
get_config_dir(home_dir).join("nushell").join("config.nu")
}
fn get_env_path(&self, home_dir: &Path) -> PathBuf {
get_config_dir(home_dir).join("nushell").join("env.nu")
}
// https://www.nushell.sh/book/configuration.html
fn get_profile_paths(&self, home_dir: &Path) -> Vec<PathBuf> {
HashSet::<PathBuf>::from_iter([
get_config_dir(home_dir).join("nushell").join("env.nu"),
home_dir.join(".config").join("nushell").join("env.nu"),
get_config_dir(home_dir).join("nushell").join("config.nu"),
home_dir.join(".config").join("nushell").join("config.nu"),
])
.into_iter()
.collect()
}

Proto treats the return value of get_profile_paths as least-preferred-comes-first, but its assumption is basically wrong.
Starbase needs to unify and clarify the order of get_profile_paths.

@tats-u tats-u changed the title The order of Shell::get_profile_paths is not consistent among shells The order of Shell::get_profile_paths is not consistent among shells; unify and clarify it Nov 19, 2024
@milesj
Copy link
Collaborator

milesj commented Nov 20, 2024

"Profile" paths can be either profile or rc files, it's not just literal profiles. I couldn't think of a better name (naming is hard lol).

I'll fix the ordering though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants