Merge remote-tracking branch 'doppioandante/set_session'
This commit is contained in:
commit
62fa133efd
|
@ -1902,6 +1902,25 @@ const CommandDesc change_working_directory_cmd = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CommandDesc change_session_name = {
|
||||||
|
"session",
|
||||||
|
nullptr,
|
||||||
|
"session <name>: change remote session name",
|
||||||
|
ParameterDesc{{}, ParameterDesc::Flags::None, 1, 1},
|
||||||
|
CommandFlags::None,
|
||||||
|
CommandHelper{},
|
||||||
|
CommandCompleter{},
|
||||||
|
[](const ParametersParser& parser, Context&, const ShellContext&)
|
||||||
|
{
|
||||||
|
if (not Server::instance().rename_session(parser[0]))
|
||||||
|
throw runtime_error(format("Cannot rename current session: '{}' may be already in use", parser[0]));
|
||||||
|
|
||||||
|
// update modeline
|
||||||
|
for (auto& client : ClientManager::instance())
|
||||||
|
client->redraw_ifn();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_commands()
|
void register_commands()
|
||||||
|
@ -1959,6 +1978,7 @@ void register_commands()
|
||||||
register_command(set_register_cmd);
|
register_command(set_register_cmd);
|
||||||
register_command(select_cmd);
|
register_command(select_cmd);
|
||||||
register_command(change_working_directory_cmd);
|
register_command(change_working_directory_cmd);
|
||||||
|
register_command(change_session_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -651,13 +651,26 @@ Server::Server(String session_name)
|
||||||
m_listener.reset(new FDWatcher{listen_sock, accepter});
|
m_listener.reset(new FDWatcher{listen_sock, accepter});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Server::rename_session(const String& name)
|
||||||
|
{
|
||||||
|
String old_socket_file = format("/tmp/kakoune/{}/{}", getpwuid(geteuid())->pw_name, m_session);
|
||||||
|
String new_socket_file = format("/tmp/kakoune/{}/{}", getpwuid(geteuid())->pw_name, name);
|
||||||
|
|
||||||
|
if (link(old_socket_file.c_str(), new_socket_file.c_str()) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
unlink(old_socket_file.c_str());
|
||||||
|
|
||||||
|
m_session = name;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Server::close_session(bool do_unlink)
|
void Server::close_session(bool do_unlink)
|
||||||
{
|
{
|
||||||
if (do_unlink)
|
if (do_unlink)
|
||||||
{
|
{
|
||||||
char socket_file[128];
|
String socket_file = format("/tmp/kakoune/{}/{}", getpwuid(geteuid())->pw_name, m_session);
|
||||||
format_to(socket_file, "/tmp/kakoune/{}/{}", getpwuid(geteuid())->pw_name, m_session);
|
unlink(socket_file.c_str());
|
||||||
unlink(socket_file);
|
|
||||||
}
|
}
|
||||||
m_listener->close_fd();
|
m_listener->close_fd();
|
||||||
m_listener.reset();
|
m_listener.reset();
|
||||||
|
|
|
@ -48,6 +48,7 @@ struct Server : public Singleton<Server>
|
||||||
~Server();
|
~Server();
|
||||||
const String& session() const { return m_session; }
|
const String& session() const { return m_session; }
|
||||||
|
|
||||||
|
bool rename_session(const String& name);
|
||||||
void close_session(bool do_unlink = true);
|
void close_session(bool do_unlink = true);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user