Add SessionRenamed hook

This commit is contained in:
Tobias Pisani 2024-03-27 17:52:31 +01:00
parent 5515383ae4
commit a1880a5441
3 changed files with 8 additions and 1 deletions

View File

@ -144,6 +144,9 @@ name. Hooks with no description will always use an empty string.
*ClientRenamed* `<old name>:<new name>`::
executed when a client is renamed using the `rename-client` command
*SessionRenamed* `<old name>:<new name>`::
executed when a session is renamed using the `rename-session` command
*RuntimeError* `error message`::
an error was encountered while executing a user command

View File

@ -2577,10 +2577,12 @@ const CommandDesc rename_session_cmd = {
CommandFlags::None,
CommandHelper{},
make_single_word_completer([](const Context&){ return Server::instance().session(); }),
[](const ParametersParser& parser, Context&, const ShellContext&)
[](const ParametersParser& parser, Context& ctx, const ShellContext&)
{
String old_name = Server::instance().session();
if (not Server::instance().rename_session(parser[0]))
throw runtime_error(format("unable to rename current session: '{}' may be already in use", parser[0]));
ctx.hooks().run_hook(Hook::SessionRenamed, format("{}:{}", old_name, Server::instance().session()), ctx);
}
};

View File

@ -31,6 +31,7 @@ enum class Hook
ClientCreate,
ClientClose,
ClientRenamed,
SessionRenamed,
InsertChar,
InsertDelete,
InsertIdle,
@ -77,6 +78,7 @@ constexpr auto enum_desc(Meta::Type<Hook>)
{Hook::ClientCreate, "ClientCreate"},
{Hook::ClientClose, "ClientClose"},
{Hook::ClientRenamed, "ClientRenamed"},
{Hook::SessionRenamed, "SessionRenamed"},
{Hook::InsertChar, "InsertChar"},
{Hook::InsertDelete, "InsertDelete"},
{Hook::InsertIdle, "InsertIdle"},