Optimize get_current_dir

Closes: https://github.com/sayanarijit/xplr/issues/628
This commit is contained in:
Arijit Basu 2023-07-07 18:55:06 +05:30
parent 255517c2a9
commit 313c61db96
No known key found for this signature in database
GPG Key ID: 0F8EF5258DC38077

View File

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