diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-12-14 12:25:10 +0100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2021-12-14 16:49:26 +0000 |
commit | 285a6908eb08f32b51e5ca9eae8a9317179d33c4 (patch) | |
tree | 1232e149de65a6dfe0a195a5f4c4a0dd1d0c6027 /src | |
parent | 020d41ce4f1dc21390db3d50148fb0c649f6c72d (diff) | |
download | systemd-285a6908eb08f32b51e5ca9eae8a9317179d33c4.tar.gz |
hostnamectl: add a chassis symbol in status output
The idea is to be able to distinguish whether we're in a VM/container or something
more substantial at a glance.
Chassis: laptop 💻
Chassis: tablet 具
Chassis: vm 🖴
Chassis: server 🖳
Chassis: handset 🕻
Chassis: watch ⌚
Chassis: desktop 🖥
Chassis: container ☐
Diffstat (limited to 'src')
-rw-r--r-- | src/hostname/hostnamectl.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index b525aaa642..58af5f186c 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -53,6 +53,26 @@ typedef struct StatusInfo { const char *hardware_model; } StatusInfo; +static const char* chassis_string_to_glyph(const char *chassis) { + if (streq_ptr(chassis, "laptop")) + return "\U0001F4BB"; /* Personal Computer */ + if (streq_ptr(chassis, "desktop")) + return "\U0001F5A5"; /* Desktop Computer */ + if (streq_ptr(chassis, "server")) + return "\U0001F5B3"; /* Old Personal Computer */ + if (streq_ptr(chassis, "tablet")) + return "\u5177"; /* Ideograph tool, implement; draw up, write, looks vaguely tabletty */ + if (streq_ptr(chassis, "watch")) + return "\u231A"; /* Watch */ + if (streq_ptr(chassis, "handset")) + return "\U0001F57B"; /* Left Hand Telephone Receiver */ + if (streq_ptr(chassis, "vm")) + return "\U0001F5B4"; /* Hard disk */ + if (streq_ptr(chassis, "container")) + return "\u2610"; /* Ballot Box */ + return NULL; +} + static int print_status_info(StatusInfo *i) { _cleanup_(table_unrefp) Table *table = NULL; sd_id128_t mid = {}, bid = {}; @@ -108,9 +128,15 @@ static int print_status_info(StatusInfo *i) { } if (!isempty(i->chassis)) { + /* Possibly add a pretty symbol. Let's not bother with non-unicode fallbacks, because this is + * just a prettification and we can't really express this with ASCII anyway. */ + const char *v = chassis_string_to_glyph(i->chassis); + if (v) + v = strjoina(i->chassis, " ", v); + r = table_add_many(table, TABLE_STRING, "Chassis:", - TABLE_STRING, i->chassis); + TABLE_STRING, v ?: i->chassis); if (r < 0) return table_log_add_error(r); } |