]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hostnamectl: add a chassis symbol in status output
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 14 Dec 2021 11:25:10 +0000 (12:25 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 14 Dec 2021 16:49:26 +0000 (16:49 +0000)
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 ☐

src/hostname/hostnamectl.c

index b525aaa642f699272bdef4bffb9e831434edbebf..58af5f186c625b4a67f5614e2a1e735b879f38f0 100644 (file)
@@ -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);
         }