Add support for listing existing sessions with kak -l

Fixes #381
This commit is contained in:
Maxime Coste 2015-08-23 14:22:23 +01:00
parent 71e362e2f9
commit a2e90c2c25
3 changed files with 15 additions and 1 deletions

View File

@ -351,6 +351,11 @@ Vector<String> list_files(StringView prefix, StringView dirname,
return result.empty() ? subseq_result : result; return result.empty() ? subseq_result : result;
} }
Vector<String> list_files(StringView directory)
{
return list_files("", directory, [](const dirent&) { return true; });
}
CandidateList complete_filename(StringView prefix, CandidateList complete_filename(StringView prefix,
const Regex& ignored_regex, const Regex& ignored_regex,
ByteCount cursor_pos) ByteCount cursor_pos)

View File

@ -48,6 +48,8 @@ void write_buffer_to_backup_file(Buffer& buffer);
String find_file(StringView filename, ConstArrayView<String> paths); String find_file(StringView filename, ConstArrayView<String> paths);
Vector<String> list_files(StringView directory);
void make_directory(StringView dir); void make_directory(StringView dir);
time_t get_fs_timestamp(StringView filename); time_t get_fs_timestamp(StringView filename);

View File

@ -580,7 +580,8 @@ int main(int argc, char* argv[])
{ "p", { true, "just send stdin as commands to the given session" } }, { "p", { true, "just send stdin as commands to the given session" } },
{ "f", { true, "act as a filter, executing given keys on given files" } }, { "f", { true, "act as a filter, executing given keys on given files" } },
{ "q", { false, "in filter mode, be quiet about errors applying keys" } }, { "q", { false, "in filter mode, be quiet about errors applying keys" } },
{ "u", { false, "use a dummy user interface, for testing purposes" } } } { "u", { false, "use a dummy user interface, for testing purposes" } },
{ "l", { false, "list existing sessions" } } }
}; };
try try
{ {
@ -590,6 +591,12 @@ int main(int argc, char* argv[])
ParametersParser parser(params, param_desc); ParametersParser parser(params, param_desc);
if (parser.get_switch("l"))
{
for (auto& file : list_files(format("/tmp/kakoune/{}/", getlogin())))
write_stdout(format("{}\n", file));
return 0;
}
if (auto session = parser.get_switch("p")) if (auto session = parser.get_switch("p"))
{ {
for (auto opt : { "c", "n", "s", "d", "e" }) for (auto opt : { "c", "n", "s", "d", "e" })