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", "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]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.8" version = "0.2.8"
@ -303,7 +293,6 @@ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"ctrlc", "ctrlc",
"dirs", "dirs",
"gethostname",
"once_cell", "once_cell",
"regex", "regex",
"rustyline", "rustyline",
@ -600,21 +589,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 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]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.42.0" version = "0.42.0"

1
Cargo.toml

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

7
src/prompt.rs

@ -1,5 +1,6 @@
use colored::Colorize; use colored::Colorize;
use std::env; use std::env;
use whoami::{hostname, username};
#[derive(Clone)] #[derive(Clone)]
pub enum PromptStyle { pub enum PromptStyle {
@ -64,11 +65,7 @@ impl PromptStyle {
.unwrap_or_default() .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