Skip to content

Commit 037802b

Browse files
committed
Add ~user
1 parent 588826a commit 037802b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
name = "sush"
3-
version = "2025.1.0"
3+
version = "2025.1.6"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
nix = { version = "0.28.0", features = ["fs", "process", "signal", "term"]}
10-
termion = "3.0.0"
9+
nix = { version = "0.28.0", features = ["fs", "process", "signal", "term", "user"]}
10+
termion = "4.0.3"
1111
unicode-width = "0.1.11"
1212
signal-hook = "0.3.17"

src/elements/word/tilde_expansion.rs

Lines changed: 12 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 nix::unistd::User;
67
use super::subword::simple::SimpleSubword;
78

89
pub fn eval(word: &mut Word, core: &mut ShellCore) {
@@ -40,8 +41,18 @@ fn get_value(text: &str, core: &mut ShellCore) -> String {
4041
"" => "HOME",
4142
"+" => "PWD",
4243
"-" => "OLDPWD",
43-
_ => return "".to_string(),
44+
_ => return get_home_dir(text),
4445
};
4546

4647
core.data.get_param(key).to_string()
4748
}
49+
50+
fn get_home_dir(user: &str) -> String {
51+
match User::from_name(user) {
52+
Ok(Some(u)) => u.dir
53+
.into_os_string()
54+
.into_string()
55+
.unwrap(),
56+
_ => String::new(),
57+
}
58+
}

0 commit comments

Comments
 (0)