From ab03434aa7b1cc174bfc75a21923165d394e47b3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 1 Feb 2024 11:13:07 +0100 Subject: [PATCH] nspawn: set window title from container name 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index ae5172853b6..2384a949455 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -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: -- 2.47.3