Browse Source

refactoring: use whoami in bash like prompt

main
fdai7381 2 years ago
parent
commit
9504af8a6f
  1. 26
      Cargo.lock
  2. 1
      Cargo.toml
  3. 7
      src/prompt.rs

26
Cargo.lock

@ -186,16 +186,6 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "gethostname"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a329e22866dd78b35d2c639a4a23d7b950aeae300dfd79f4fb19f74055c2404"
dependencies = [
"libc",
"windows",
]
[[package]]
name = "getrandom"
version = "0.2.8"
@ -303,7 +293,6 @@ dependencies = [
"crossbeam-channel",
"ctrlc",
"dirs",
"gethostname",
"once_cell",
"regex",
"rustyline",
@ -600,21 +589,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.43.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04662ed0e3e5630dfa9b26e4cb823b817f1a9addda855d973a9458c236556244"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows-sys"
version = "0.42.0"

1
Cargo.toml

@ -8,7 +8,6 @@ colored = "2.0"
crossbeam-channel = "0.5"
ctrlc = "3.2"
dirs = "4.0"
gethostname = "0.4"
once_cell = "1.17"
regex = "1.7"
rustyline = "10.1"

7
src/prompt.rs

@ -1,5 +1,6 @@
use colored::Colorize;
use std::env;
use whoami::{hostname, username};
#[derive(Clone)]
pub enum PromptStyle {
@ -64,11 +65,7 @@ impl PromptStyle {
.unwrap_or_default()
};
let username = home.file_name().unwrap_or_default().to_string_lossy();
let _hostname = gethostname::gethostname();
let hostname = _hostname.to_string_lossy();
format!("[{}@{} {}]$ ", username, hostname, dir_as_string)
format!("[{}@{} {}]$ ", username(), hostname(), dir_as_string)
}
}

Loading…
Cancel
Save