Optimize get_current_dir

Closes: https://github.com/sayanarijit/xplr/issues/628
pull/649/head
Arijit Basu 11 months ago
parent 255517c2a9
commit 313c61db96
No known key found for this signature in database
GPG Key ID: 0F8EF5258DC38077

@ -40,15 +40,14 @@ pub fn get_tty() -> Result<fs::File> {
// returns physical path. As a workaround, this function tries to use `PWD` // returns physical path. As a workaround, this function tries to use `PWD`
// environment variable that is configured by shell. // environment variable that is configured by shell.
fn get_current_dir() -> Result<PathBuf, std::io::Error> { fn get_current_dir() -> Result<PathBuf, std::io::Error> {
let cur = std::env::current_dir();
if let Ok(pwd) = std::env::var("PWD") { if let Ok(pwd) = std::env::var("PWD") {
if pwd.is_empty() { if pwd.is_empty() {
cur std::env::current_dir()
} else { } else {
Ok(PathBuf::from(pwd)) Ok(PathBuf::from(pwd))
} }
} else { } else {
cur std::env::current_dir()
} }
} }

Loading…
Cancel
Save