From 3827fc4543f55ff33ed657625b68ca628917188c Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 1 Sep 2026 08:13:05 +0000 Subject: hostname support --- include/util/prompt.h | 5 ++++- src/util/prompt.cc | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/util/prompt.h b/include/util/prompt.h index 464156a..6cdcfb8 100644 --- a/include/util/prompt.h +++ b/include/util/prompt.h @@ -6,8 +6,11 @@ namespace ov4 { - constexpr std::string_view prompt = "$"; + constexpr std::string_view prompt_normal = "$"; + constexpr std::string_view prompt_root = "#"; + constexpr size_t hostname_size = 128; extern bool emit_prompt; void print_prompt(); + std::string get_prompt(); } diff --git a/src/util/prompt.cc b/src/util/prompt.cc index 8f4e5e1..977cb0b 100644 --- a/src/util/prompt.cc +++ b/src/util/prompt.cc @@ -10,7 +10,25 @@ namespace ov4 { if (emit_prompt) { - cout << name << " : " << get_current_dir() << " " << prompt << " " << flush; + char buffer[hostname_size]; + gethostname(buffer, hostname_size); + cout + << name + << " " + << getlogin() + << "@" + << buffer + << ":" + << get_current_dir() + << " " + << get_prompt() + << " " + << flush; } } + + string get_prompt() + { + return (string)((string)(getlogin()) == "root" ? prompt_root : prompt_normal); + } } -- cgit v1.3.1-4-g156e