]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: set window title from container name
authorLennart Poettering <lennart@poettering.net>
Thu, 1 Feb 2024 10:13:07 +0000 (11:13 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 9 Feb 2024 17:27:01 +0000 (18:27 +0100)
Let's update the window title with an ANSI sequence if we can. We'll
insert a blue dot, to match the blue tinting of the terminal screen,
indicating that we are in a container.

src/nspawn/nspawn.c

index ae5172853b6aed2a3fafa4f71072346656c8561a..2384a94945555705c2a91d80f2554feba379220e 100644 (file)
@@ -4451,6 +4451,22 @@ static int setup_notify_parent(sd_event *event, int fd, pid_t *inner_child_pid,
         return 0;
 }
 
+static void set_window_title(PTYForward *f) {
+        _cleanup_free_ char *hn = NULL, *dot = NULL;
+
+        assert(f);
+
+        (void) gethostname_strict(&hn);
+
+        if (emoji_enabled())
+                dot = strjoin(special_glyph(SPECIAL_GLYPH_BLUE_CIRCLE), " ");
+
+        if (hn)
+                (void) pty_forward_set_titlef(f, "%sContainer %s on %s", strempty(dot), arg_machine, hn);
+        else
+                (void) pty_forward_set_titlef(f, "%sContainer %s", strempty(dot), arg_machine);
+}
+
 static int merge_settings(Settings *settings, const char *path) {
         int rl;
 
@@ -5383,6 +5399,7 @@ static int run_container(
                         } else if (!isempty(arg_background))
                                 (void) pty_forward_set_background_color(forward, arg_background);
 
+                        set_window_title(forward);
                         break;
 
                 default: