Skip to content

Commit

Permalink
allow for "~/" #100
Browse files Browse the repository at this point in the history
  • Loading branch information
jhspetersson committed Apr 17, 2021
1 parent ae6b2c7 commit 9acc5db
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::query::OutputFormat;
use crate::query::Query;
use crate::query::Root;
use crate::query::TraversalMode::{Bfs, Dfs};
use std::path::PathBuf;
use directories::UserDirs;

pub struct Parser {
lexems: Vec<Lexem>,
Expand Down Expand Up @@ -161,6 +163,14 @@ impl Parser {
match mode {
RootParsingMode::From | RootParsingMode::Comma => {
path = s.to_string();
if path.starts_with("~") {
let mut pb = PathBuf::from(path.clone());
pb = pb.components().skip(1).collect();
if let Some(ud) = UserDirs::new() {
pb = ud.home_dir().to_path_buf().join(pb);
path = pb.to_string_lossy().to_string();
}
}
mode = RootParsingMode::Root;
},
RootParsingMode::Root | RootParsingMode::Options => {
Expand Down

0 comments on commit 9acc5db

Please sign in to comment.