add a runtime command to execute files in the runtime directory
This commit is contained in:
parent
f99c3a1a6a
commit
c62b3b251d
28
src/main.cc
28
src/main.cc
|
@ -598,6 +598,23 @@ void exec_commands_in_file(const CommandParameters& params,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void exec_commands_in_runtime_file(const CommandParameters& params,
|
||||||
|
const Context& context)
|
||||||
|
{
|
||||||
|
if (params.size() != 1)
|
||||||
|
throw wrong_argument_count();
|
||||||
|
|
||||||
|
const std::string& filename = params[0];
|
||||||
|
char buffer[2048];
|
||||||
|
readlink("/proc/self/exe", buffer, 2048 - filename.length());
|
||||||
|
char* ptr = strrchr(buffer, '/');
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
strcpy(ptr+1, filename.c_str());
|
||||||
|
exec_commands_in_file({ buffer }, main_context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void do_command()
|
void do_command()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -949,6 +966,7 @@ int main(int argc, char* argv[])
|
||||||
command_manager.register_command(std::vector<std::string>{ "source" }, exec_commands_in_file,
|
command_manager.register_command(std::vector<std::string>{ "source" }, exec_commands_in_file,
|
||||||
CommandManager::None,
|
CommandManager::None,
|
||||||
PerArgumentCommandCompleter{ complete_filename });
|
PerArgumentCommandCompleter{ complete_filename });
|
||||||
|
command_manager.register_command(std::vector<std::string>{ "runtime" }, exec_commands_in_runtime_file);
|
||||||
|
|
||||||
command_manager.register_command(std::vector<std::string>{ "exec" }, exec_string);
|
command_manager.register_command(std::vector<std::string>{ "exec" }, exec_string);
|
||||||
|
|
||||||
|
@ -957,15 +975,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const char* kakrc = "kakrc";
|
exec_commands_in_runtime_file({ "kakrc" }, main_context);
|
||||||
char buffer[2048];
|
|
||||||
readlink("/proc/self/exe", buffer, 2048 - strlen(kakrc));
|
|
||||||
char* ptr = strrchr(buffer, '/');
|
|
||||||
if (ptr)
|
|
||||||
{
|
|
||||||
strcpy(ptr+1, kakrc);
|
|
||||||
exec_commands_in_file({ buffer }, main_context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& error)
|
catch (Kakoune::runtime_error& error)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user