From fcf3ec2877f042c6957d808e562807089e23ebe6 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 9 Apr 2024 08:58:58 +0100 Subject: ash: add title built-in Implement a 'title' built-in for ash. It's very simple-minded, performs almost no error checking and is completely non-portable. - With no arguments it prints the current console title. - If arguments are provided the *first only* is set as the console title. Costs 88-116 bytes. (GitHub issue #401) --- shell/ash.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index d312cb8cd..df27e9c8d 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -11253,6 +11253,9 @@ static int readcmd(int, char **) FAST_FUNC; static int setcmd(int, char **) FAST_FUNC; static int shiftcmd(int, char **) FAST_FUNC; static int timescmd(int, char **) FAST_FUNC; +#if ENABLE_PLATFORM_MINGW32 +static int titlecmd(int, char **) FAST_FUNC; +#endif static int trapcmd(int, char **) FAST_FUNC; static int umaskcmd(int, char **) FAST_FUNC; static int unsetcmd(int, char **) FAST_FUNC; @@ -11352,6 +11355,9 @@ static const struct builtincmd builtintab[] = { { BUILTIN_REGULAR "test" , testcmd }, #endif { BUILTIN_SPEC_REG "times" , timescmd }, +#if ENABLE_PLATFORM_MINGW32 + { BUILTIN_REGULAR "title" , titlecmd }, +#endif { BUILTIN_SPEC_REG "trap" , trapcmd }, { BUILTIN_REGULAR "true" , truecmd }, { BUILTIN_REGULAR "type" , typecmd }, @@ -15549,6 +15555,21 @@ timescmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) return 0; } +#if ENABLE_PLATFORM_MINGW32 +static int FAST_FUNC +titlecmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) +{ + if (*argptr == NULL) { + char buffer[256]; + if (get_title(buffer, sizeof(buffer))) + puts(buffer); + } else { + set_title(*argptr); + } + return 0; +} +#endif + #if ENABLE_FEATURE_SH_MATH /* * The let builtin. Partially stolen from GNU Bash, the Bourne Again SHell. -- cgit v1.2.3-55-g6feb