diff --git a/src/cascadia/TerminalApp/AppCommandlineArgs.cpp b/src/cascadia/TerminalApp/AppCommandlineArgs.cpp index e9b6368ff0b..2fa36a9711f 100644 --- a/src/cascadia/TerminalApp/AppCommandlineArgs.cpp +++ b/src/cascadia/TerminalApp/AppCommandlineArgs.cpp @@ -568,6 +568,9 @@ void AppCommandlineArgs::_addNewTerminalArgs(AppCommandlineArgs::NewTerminalSubc subcommand.colorSchemeOption = subcommand.subcommand->add_option("--colorScheme", _startingColorScheme, RS_A(L"CmdColorSchemeArgDesc")); + + subcommand.appendCommandLineOption = subcommand.subcommand->add_flag("--appendCommandLine", _appendCommandLineOption, RS_A(L"CmdAppendCommandLineDesc")); + // Using positionals_at_end allows us to support "wt new-tab -d wsl -d Ubuntu" // without CLI11 thinking that we've specified -d twice. // There's an alternate construction where we make all subcommands "prefix commands", @@ -654,6 +657,10 @@ NewTerminalArgs AppCommandlineArgs::_getNewTerminalArgs(AppCommandlineArgs::NewT { args.ColorScheme(winrt::to_hstring(_startingColorScheme)); } + if (*subcommand.appendCommandLineOption) + { + args.AppendCommandLine(_appendCommandLineOption); + } return args; } @@ -699,6 +706,7 @@ void AppCommandlineArgs::_resetStateToDefault() _startingTabColor.clear(); _commandline.clear(); _suppressApplicationTitle = false; + _appendCommandLineOption = false; _splitVertical = false; _splitHorizontal = false; diff --git a/src/cascadia/TerminalApp/AppCommandlineArgs.h b/src/cascadia/TerminalApp/AppCommandlineArgs.h index 31eac78168b..292a3500c42 100644 --- a/src/cascadia/TerminalApp/AppCommandlineArgs.h +++ b/src/cascadia/TerminalApp/AppCommandlineArgs.h @@ -67,6 +67,7 @@ class TerminalApp::AppCommandlineArgs final CLI::Option* tabColorOption; CLI::Option* suppressApplicationTitleOption; CLI::Option* colorSchemeOption; + CLI::Option* appendCommandLineOption; }; struct NewPaneSubcommand : public NewTerminalSubcommand @@ -105,6 +106,7 @@ class TerminalApp::AppCommandlineArgs final // _commandline will contain the command line with which we'll be spawning a new terminal std::vector _commandline; + bool _appendCommandLineOption{ false }; bool _splitVertical{ false }; bool _splitHorizontal{ false }; diff --git a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw index 80f0a9df574..6834eff5847 100644 --- a/src/cascadia/TerminalApp/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalApp/Resources/en-US/Resources.resw @@ -840,4 +840,7 @@ Run as Administrator This text is displayed on context menu for profile entries in add new tab button. - \ No newline at end of file + + If set, the command will be appended to the profile's default command instead of replacing it. + + diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.h b/src/cascadia/TerminalSettingsModel/ActionArgs.h index 87e1ac4fcfe..5633c039469 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.h +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.h @@ -309,6 +309,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation ACTION_ARG(Windows::Foundation::IReference, TabColor, nullptr); ACTION_ARG(Windows::Foundation::IReference, ProfileIndex, nullptr); ACTION_ARG(winrt::hstring, Profile, L""); + ACTION_ARG(bool, AppendCommandLine, false); ACTION_ARG(Windows::Foundation::IReference, SuppressApplicationTitle, nullptr); ACTION_ARG(winrt::hstring, ColorScheme); ACTION_ARG(Windows::Foundation::IReference, Elevate, nullptr); @@ -320,6 +321,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static constexpr std::string_view TabColorKey{ "tabColor" }; static constexpr std::string_view ProfileIndexKey{ "index" }; static constexpr std::string_view ProfileKey{ "profile" }; + static constexpr std::string_view AppendCommandLineKey{ "appendCommandLine" }; static constexpr std::string_view SuppressApplicationTitleKey{ "suppressApplicationTitle" }; static constexpr std::string_view ColorSchemeKey{ "colorScheme" }; static constexpr std::string_view ElevateKey{ "elevate" }; @@ -340,6 +342,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation otherAsUs->_TabColor == _TabColor && otherAsUs->_ProfileIndex == _ProfileIndex && otherAsUs->_Profile == _Profile && + otherAsUs->_AppendCommandLine == _AppendCommandLine && otherAsUs->_SuppressApplicationTitle == _SuppressApplicationTitle && otherAsUs->_ColorScheme == _ColorScheme && otherAsUs->_Elevate == _Elevate && diff --git a/src/cascadia/TerminalSettingsModel/ActionArgs.idl b/src/cascadia/TerminalSettingsModel/ActionArgs.idl index d38e3011281..271c9d979d8 100644 --- a/src/cascadia/TerminalSettingsModel/ActionArgs.idl +++ b/src/cascadia/TerminalSettingsModel/ActionArgs.idl @@ -132,6 +132,7 @@ namespace Microsoft.Terminal.Settings.Model String TabTitle; Windows.Foundation.IReference TabColor; String Profile; // Either a GUID or a profile's name if the GUID isn't a match + Boolean AppendCommandLine; // We use IReference<> to treat some args as nullable where null means // "use the inherited value". See ProfileIndex, diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index aaa151d9cf2..c594d42fb3b 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -129,7 +129,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation // Override commandline, starting directory if they exist in newTerminalArgs if (!newTerminalArgs.Commandline().empty()) { - defaultSettings.Commandline(newTerminalArgs.Commandline()); + if (!newTerminalArgs.AppendCommandLine()) + { + defaultSettings.Commandline(newTerminalArgs.Commandline()); + } + else + { + defaultSettings.Commandline(defaultSettings.Commandline() + L" " + newTerminalArgs.Commandline()); + } } if (!newTerminalArgs.StartingDirectory().empty()) {