summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin Song <chipbuster@users.noreply.github.com>2019-09-20 11:28:09 -0500
committerMatan Kushner <hello@matchai.me>2019-09-20 12:28:09 -0400
commitc2875d99b678c547c15681e85a4a96d9d264989a (patch)
treec6666e6b453223a97636f731ef3515b11f6d4d57 /src
parentcd892ebb60231cce84bd5c2cfed280571026ad9d (diff)
feat: add support for logical paths in directory (#366)
Adds the ability for starship to display the logical path instead of the physical path.
Diffstat (limited to 'src')
-rw-r--r--src/modules/directory.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/modules/directory.rs b/src/modules/directory.rs
index fa6b5c7a3..01cd6c011 100644
--- a/src/modules/directory.rs
+++ b/src/modules/directory.rs
@@ -32,8 +32,26 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
.config_value_i64("fish_style_pwd_dir_length")
.unwrap_or(FISH_STYLE_PWD_DIR_LENGTH);
+ // Using environment PWD is the standard approach for determining logical path
+ let use_logical_path = module.config_value_bool("use_logical_path").unwrap_or(true);
+ // If this is None for any reason, we fall back to reading the os-provided path
+ let logical_current_dir = if use_logical_path {
+ match std::env::var("PWD") {
+ Ok(x) => Some(x),
+ Err(_) => {
+ log::debug!("Asked for logical path, but PWD was invalid.");
+ None
+ }
+ }
+ } else {
+ None
+ };
+ let current_dir = logical_current_dir
+ .as_ref()
+ .map(|d| Path::new(d))
+ .unwrap_or_else(|| context.current_dir.as_ref());
+
let home_dir = dirs::home_dir().unwrap();
- let current_dir = &context.current_dir;
log::debug!("Current directory: {:?}", current_dir);
let repo = &context.get_repo().ok()?;
@@ -54,7 +72,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
if fish_style_pwd_dir_length > 0 {
// If user is using fish style path, we need to add the segment first
- let contracted_home_dir = contract_path(current_dir, &home_dir, HOME_SYMBOL);
+ let contracted_home_dir = contract_path(&current_dir, &home_dir, HOME_SYMBOL);
let fish_style_dir = to_fish_style(
fish_style_pwd_dir_length as usize,
contracted_home_dir,