summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFrank LENORMAND <lenormf@gmail.com>2017-03-22 16:47:25 +0300
committerFrank LENORMAND <lenormf@gmail.com>2017-03-23 08:50:43 +0300
commit6b8587000b99ff973ea38cb8aa713bfb2c7502d2 (patch)
tree23b42d80eee5e8ad35714b07d2ac1412e37f74b3 /src
parent5a403a961149e51f344233c901bee5da9e7cac0a (diff)
src: Introduce a `-i` suffix flag for filter backups
This commit allows the user to chose to backup the files on which a filter has been run, by specifying a suffix for the backup file. The former implementation always backed up the files with a hardcoded ".kak-bak" suffix. When no suffix is specified on the command line, the files are not saved. Fixes #1288
Diffstat (limited to 'src')
-rw-r--r--src/main.cc9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/main.cc b/src/main.cc
index b592a7b3..a21be6c5 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -642,7 +642,7 @@ int run_server(StringView session,
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;
GlobalScope global_scope;
@@ -689,7 +689,8 @@ int run_filter(StringView keystr, StringView commands, ConstArrayView<StringView
for (auto& file : files)
{
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);
write_buffer_to_file(*buffer, file);
buffer_manager.delete_buffer(*buffer);
@@ -796,6 +797,7 @@ int main(int argc, char* argv[])
{ "d", { false, "run as a headless session (requires -s)" } },
{ "p", { true, "just send stdin as commands to the given session" } },
{ "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" } },
{ "ui", { true, "set the type of user interface to use (ncurses, dummy, or json)" } },
{ "l", { false, "list existing sessions" } },
@@ -862,7 +864,8 @@ int main(int argc, char* argv[])
files.emplace_back(parser[i]);
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;