From a2e90c2c2570e432d4c71a15cdb2cacd1a7c0407 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 23 Aug 2015 14:22:23 +0100 Subject: [PATCH] Add support for listing existing sessions with kak -l Fixes #381 --- src/file.cc | 5 +++++ src/file.hh | 2 ++ src/main.cc | 9 ++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/file.cc b/src/file.cc index 2c8afeb5..041d653f 100644 --- a/src/file.cc +++ b/src/file.cc @@ -351,6 +351,11 @@ Vector list_files(StringView prefix, StringView dirname, return result.empty() ? subseq_result : result; } +Vector list_files(StringView directory) +{ + return list_files("", directory, [](const dirent&) { return true; }); +} + CandidateList complete_filename(StringView prefix, const Regex& ignored_regex, ByteCount cursor_pos) diff --git a/src/file.hh b/src/file.hh index 5cbdc778..ef51c2d8 100644 --- a/src/file.hh +++ b/src/file.hh @@ -48,6 +48,8 @@ void write_buffer_to_backup_file(Buffer& buffer); String find_file(StringView filename, ConstArrayView paths); +Vector list_files(StringView directory); + void make_directory(StringView dir); time_t get_fs_timestamp(StringView filename); diff --git a/src/main.cc b/src/main.cc index 2a4b96ac..fb0741fa 100644 --- a/src/main.cc +++ b/src/main.cc @@ -580,7 +580,8 @@ int main(int argc, char* argv[]) { "p", { true, "just send stdin as commands to the given session" } }, { "f", { true, "act as a filter, executing given keys on given files" } }, { "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 { @@ -590,6 +591,12 @@ int main(int argc, char* argv[]) 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")) { for (auto opt : { "c", "n", "s", "d", "e" })