Skip to content

Commit 0c26725

Browse files
committed
Implement ~ ~+ ~-
1 parent 55c453f commit 0c26725

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/elements/subword.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
mod escaped_char;
55
pub mod parameter;
6-
mod simple;
6+
pub mod simple;
77
mod single_quoted;
88
mod varname;
99

src/elements/word/tilde_expansion.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use crate::ShellCore;
55
use crate::elements::word::Word;
6+
use crate::elements::subword::simple::SimpleSubword;
67

78
pub fn eval(word: &mut Word, core: &mut ShellCore) {
89
let length = match prefix_length(word) {
@@ -15,7 +16,12 @@ pub fn eval(word: &mut Word, core: &mut ShellCore) {
1516
.collect::<Vec<String>>()
1617
.concat();
1718

18-
eprintln!("PREFIX: {}", text);
19+
let value = get_value(&text, core);
20+
if value == "" {
21+
return;
22+
}
23+
word.subwords[0] = Box::new( SimpleSubword{ text: value } );
24+
word.subwords[1..length].iter_mut().for_each(|w| w.set_text(""));
1925
}
2026

2127
fn prefix_length(word: &Word) -> usize {
@@ -28,3 +34,14 @@ fn prefix_length(word: &Word) -> usize {
2834
Some(n) => n,
2935
}
3036
}
37+
38+
fn get_value(text: &str, core: &mut ShellCore) -> String {
39+
let key = match text {
40+
"" => "HOME",
41+
"+" => "PWD",
42+
"-" => "OLDPWD",
43+
_ => return "".to_string(),
44+
};
45+
46+
core.data.get_param(key).to_string()
47+
}

0 commit comments

Comments
 (0)