From: Lennart Poettering Date: Thu, 1 Feb 2024 10:13:07 +0000 (+0100) Subject: nspawn: set window title from container name X-Git-Tag: v256-rc1~893^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ab03434aa7b1cc174bfc75a21923165d394e47b3;p=thirdparty%2Fsystemd.git 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. --- 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: