From 486582a7307cf845ee52fcb6f9ede2d92c69ed86 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 9 Mar 2019 11:40:42 +0000 Subject: su: change title of console window --- include/mingw.h | 1 + loginutils/suw32.c | 4 +++- shell/ash.c | 14 +++++++++++++- win32/winansi.c | 6 ++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/mingw.h b/include/mingw.h index 52759b7b1..ead07ae82 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -144,6 +144,7 @@ int mingw_pclose(FILE *fd); * ANSI emulation wrappers */ +void set_title(const char *str); void move_cursor_row(int n); void reset_screen(void); int winansi_putchar(int c); diff --git a/loginutils/suw32.c b/loginutils/suw32.c index 93fd145f1..787bcbbef 100644 --- a/loginutils/suw32.c +++ b/loginutils/suw32.c @@ -49,7 +49,9 @@ int suw32_main(int argc UNUSED_PARAM, char **argv) info.lpFile = bb_path; /* ShellExecuteEx() always runs system binaries in C:\Windows\System32. * Pass the directory we want to the shell. */ - info.lpParameters = xasprintf("--busybox ash -d \"%s\"", getcwd(NULL, 0)); + info.lpParameters = + xasprintf("--busybox ash -d \"%s\" -t \"BusyBox ash (su)\" ", + getcwd(NULL, 0)); if (opt_command) info.lpParameters = xasprintf("%s -s -c \"%s\"", info.lpParameters, opt_command); diff --git a/shell/ash.c b/shell/ash.c index b7fb29452..6b70dcde3 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -482,6 +482,7 @@ struct globals_misc { char *minusc; /* argument to -c option */ #if ENABLE_PLATFORM_MINGW32 char *dirarg; /* argument to -d option */ + char *title; /* argument to -t option */ #endif char *curdir; // = nullstr; /* current working directory */ @@ -578,6 +579,7 @@ extern struct globals_misc *BB_GLOBAL_CONST ash_ptr_to_globals_misc; #define minusc (G_misc.minusc ) #if ENABLE_PLATFORM_MINGW32 #define dirarg (G_misc.dirarg ) +#define title (G_misc.title ) #endif #define curdir (G_misc.curdir ) #define physdir (G_misc.physdir ) @@ -11682,6 +11684,7 @@ options(int cmdline, int *login_sh) minusc = NULL; #if ENABLE_PLATFORM_MINGW32 dirarg = NULL; + title = NULL; #endif } while ((p = *argptr) != NULL) { @@ -11710,12 +11713,18 @@ options(int cmdline, int *login_sh) if (c == 'c' && cmdline) { minusc = p; /* command is after shell args */ #if ENABLE_PLATFORM_MINGW32 - /* Undocumented -d option to force current directory. + /* Undocumented flags; + * -d force current directory + * -t title to display in console window * Must appear before -s or -c. */ } else if (c == 'd' && cmdline && val == 1) { if (*argptr == NULL) ash_msg_and_raise_error(bb_msg_requires_arg, "-d"); dirarg = *argptr++; + } else if (c == 't' && cmdline && val == 1) { + if (*argptr == NULL) + ash_msg_and_raise_error(bb_msg_requires_arg, "-t"); + title = *argptr++; #endif } else if (c == 'o') { if (plus_minus_o(*argptr, val)) { @@ -14979,6 +14988,9 @@ int ash_main(int argc UNUSED_PARAM, char **argv) chdir(dirarg); setpwd(NULL, 0); } + + if (title) + set_title(title); #endif if (login_sh) { diff --git a/win32/winansi.c b/win32/winansi.c index e0ae38a91..08d37335b 100644 --- a/win32/winansi.c +++ b/win32/winansi.c @@ -85,6 +85,12 @@ static int skip_ansi_emulation(void) return var != NULL; } +void set_title(const char *str) +{ + if (is_console(STDOUT_FILENO)) + SetConsoleTitle(str); +} + #define FOREGROUND_ALL (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) #define BACKGROUND_ALL (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE) -- cgit v1.2.3-55-g6feb