Feat: pwd
This commit is contained in:
parent
c34accce65
commit
61f1545ff2
|
@ -0,0 +1,36 @@
|
||||||
|
use std::{env, fs, process::exit};
|
||||||
|
fn main() {
|
||||||
|
let mut args: Vec<String> = env::args().collect();
|
||||||
|
args.remove(0);
|
||||||
|
let mut output = Output::Logical;
|
||||||
|
for i in args {
|
||||||
|
if &i[..] == "-L" {
|
||||||
|
output = Output::Logical;
|
||||||
|
} else if &i[..] == "-P" {
|
||||||
|
output = Output::Physical;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match output {
|
||||||
|
| Output::Logical => println!("{}", get_logical_dir()),
|
||||||
|
| Output::Physical => {
|
||||||
|
println!("{}", fs::canonicalize(get_logical_dir()).unwrap().to_string_lossy())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_logical_dir() -> String {
|
||||||
|
// current_dir follows symlinks which isn't what we want with
|
||||||
|
// logical pwd.
|
||||||
|
match env::var("PWD") {
|
||||||
|
| Ok(d) => d,
|
||||||
|
| Err(e) => {
|
||||||
|
eprintln!("Could not read environment variable $PWD: {}", e);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Output {
|
||||||
|
Logical,
|
||||||
|
Physical
|
||||||
|
}
|
Loading…
Reference in New Issue