Skip to content

Commit

Permalink
Add ~user
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Oct 18, 2024
1 parent 588826a commit 037802b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "sush"
version = "2025.1.0"
version = "2025.1.6"
edition = "2021"

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

[dependencies]
nix = { version = "0.28.0", features = ["fs", "process", "signal", "term"]}
termion = "3.0.0"
nix = { version = "0.28.0", features = ["fs", "process", "signal", "term", "user"]}
termion = "4.0.3"
unicode-width = "0.1.11"
signal-hook = "0.3.17"
13 changes: 12 additions & 1 deletion src/elements/word/tilde_expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use crate::ShellCore;
use crate::elements::word::Word;
use nix::unistd::User;
use super::subword::simple::SimpleSubword;

pub fn eval(word: &mut Word, core: &mut ShellCore) {
Expand Down Expand Up @@ -40,8 +41,18 @@ fn get_value(text: &str, core: &mut ShellCore) -> String {
"" => "HOME",
"+" => "PWD",
"-" => "OLDPWD",
_ => return "".to_string(),
_ => return get_home_dir(text),
};

core.data.get_param(key).to_string()
}

fn get_home_dir(user: &str) -> String {
match User::from_name(user) {
Ok(Some(u)) => u.dir
.into_os_string()
.into_string()
.unwrap(),
_ => String::new(),
}
}

0 comments on commit 037802b

Please sign in to comment.