|
@ -4,6 +4,7 @@ use std::env; |
|
|
pub enum PromptStyle {
|
|
|
pub enum PromptStyle {
|
|
|
None,
|
|
|
None,
|
|
|
SimpleDirectory,
|
|
|
SimpleDirectory,
|
|
|
|
|
|
BashLike,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl PromptStyle {
|
|
|
impl PromptStyle {
|
|
@ -11,6 +12,7 @@ impl PromptStyle { |
|
|
match self {
|
|
|
match self {
|
|
|
PromptStyle::None => self.fmt_none(),
|
|
|
PromptStyle::None => self.fmt_none(),
|
|
|
PromptStyle::SimpleDirectory => self.fmt_simple_directory(),
|
|
|
PromptStyle::SimpleDirectory => self.fmt_simple_directory(),
|
|
|
|
|
|
PromptStyle::BashLike => self.fmt_bash_like(),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@ -23,6 +25,26 @@ impl PromptStyle { |
|
|
|
|
|
|
|
|
return format!("{} » ", path.to_string_lossy());
|
|
|
return format!("{} » ", path.to_string_lossy());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn fmt_bash_like(&self) -> String {
|
|
|
|
|
|
let path = env::current_dir().unwrap_or_default();
|
|
|
|
|
|
let home = dirs::home_dir().unwrap_or_default();
|
|
|
|
|
|
|
|
|
|
|
|
let dir_as_string = if path == home {
|
|
|
|
|
|
"~"
|
|
|
|
|
|
} else {
|
|
|
|
|
|
path.file_name()
|
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
|
.to_str()
|
|
|
|
|
|
.unwrap_or_default()
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let username = home.file_name().unwrap_or_default().to_string_lossy();
|
|
|
|
|
|
let _hostname = gethostname::gethostname();
|
|
|
|
|
|
let hostname = _hostname.to_string_lossy();
|
|
|
|
|
|
|
|
|
|
|
|
return format!("[{}@{} {}]$ ", username, hostname, dir_as_string);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub struct Prompt {
|
|
|
pub struct Prompt {
|
|
|