Merge remote-tracking branch 'lenormf/fix-filter-backup-suffix'

This commit is contained in:
Maxime Coste 2017-04-10 21:39:24 +01:00
commit 112bd156e4

View File

@ -643,7 +643,7 @@ int run_server(StringView session,
return 0; return 0;
} }
int run_filter(StringView keystr, StringView commands, ConstArrayView<StringView> files, bool quiet) int run_filter(StringView keystr, StringView commands, ConstArrayView<StringView> files, bool quiet, StringView suffix_backup)
{ {
StringRegistry string_registry; StringRegistry string_registry;
GlobalScope global_scope; GlobalScope global_scope;
@ -690,7 +690,8 @@ int run_filter(StringView keystr, StringView commands, ConstArrayView<StringView
for (auto& file : files) for (auto& file : files)
{ {
Buffer* buffer = open_file_buffer(file); Buffer* buffer = open_file_buffer(file);
write_buffer_to_file(*buffer, file + ".kak-bak"); if (not suffix_backup.empty())
write_buffer_to_file(*buffer, file + suffix_backup);
apply_to_buffer(*buffer); apply_to_buffer(*buffer);
write_buffer_to_file(*buffer, file); write_buffer_to_file(*buffer, file);
buffer_manager.delete_buffer(*buffer); buffer_manager.delete_buffer(*buffer);
@ -797,6 +798,7 @@ int main(int argc, char* argv[])
{ "d", { false, "run as a headless session (requires -s)" } }, { "d", { false, "run as a headless session (requires -s)" } },
{ "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" } },
{ "i", { true, "backup the files on which a filter is applied using the given suffix" } },
{ "q", { false, "in filter mode, be quiet about errors applying keys" } }, { "q", { false, "in filter mode, be quiet about errors applying keys" } },
{ "ui", { true, "set the type of user interface to use (ncurses, dummy, or json)" } }, { "ui", { true, "set the type of user interface to use (ncurses, dummy, or json)" } },
{ "l", { false, "list existing sessions" } }, { "l", { false, "list existing sessions" } },
@ -880,7 +882,8 @@ int main(int argc, char* argv[])
files.emplace_back(parser[i]); files.emplace_back(parser[i]);
return run_filter(*keys, init_cmds, files, return run_filter(*keys, init_cmds, files,
(bool)parser.get_switch("q")); (bool)parser.get_switch("q"),
parser.get_switch("i").value_or(StringView{}));
} }
Vector<StringView> files; Vector<StringView> files;