mirror of
https://github.com/sayanarijit/xplr
synced 2024-11-10 07:10:45 +00:00
Change to use PWD
env vairable to get current dir
Fixes 285.
This commit is contained in:
parent
00030e44ff
commit
f5131b08ab
@ -115,6 +115,22 @@ pub struct Runner {
|
||||
selection: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
// In unix system, the std::env::current_dir() calls libc getcwd() that
|
||||
// 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
|
||||
} else {
|
||||
Ok(PathBuf::from(pwd))
|
||||
}
|
||||
} else {
|
||||
cur
|
||||
}
|
||||
}
|
||||
|
||||
impl Runner {
|
||||
/// Create a new runner object passing the default arguments
|
||||
pub fn new() -> Result<Self> {
|
||||
@ -123,7 +139,7 @@ impl Runner {
|
||||
|
||||
/// Create a new runner object passing the given arguments
|
||||
pub fn from_cli(cli: Cli) -> Result<Self> {
|
||||
let basedir = std::env::current_dir()?;
|
||||
let basedir = get_current_dir()?;
|
||||
let basedir_clone = basedir.clone();
|
||||
let mut paths = cli.paths.into_iter().map(|p| {
|
||||
if p.is_relative() {
|
||||
|
Loading…
Reference in New Issue
Block a user