From 1a9f87f584d37ccea3ea84b788a4eb36321ccbb9 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 26 Jun 2018 16:22:13 +0200 Subject: [vis] add suw plugin to write as root --- config/vis/plugins/suw.lua | 32 ++++++++++++++++++++++++++++++++ config/vis/visrc.lua | 5 +++-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 config/vis/plugins/suw.lua diff --git a/config/vis/plugins/suw.lua b/config/vis/plugins/suw.lua new file mode 100644 index 0000000..b68e123 --- /dev/null +++ b/config/vis/plugins/suw.lua @@ -0,0 +1,32 @@ +--- a module for writing to to a file by increasing privilege +-- @author [Alejandro Baez](https://twitter.com/a_baez) +-- @module suw + +--- cmd for sudo write and quit +local suwq = function() + local file = vis.win.file + vis:command((", > sudo tee %s"):format(file.name)) + + vis:command("q!") +end + +--- cmd for sudo write +local suw = function() + local file = vis.win.file + vis:command((", > sudo tee %s"):format(file.name)) + + vis.events.emit(vis.events.FILE_SAVE_PRE, function(...) return true end) + vis.events.emit(vis.events.FILE_SAVE_POST, function(...) + file.modified = false + end) +end + +local function main() + local comment = "write to file with privilege" + + vis:command_register("suw", suw, comment) + vis:command_register("suwq", suwq, comment .. " and quit") +end + + +return main() \ No newline at end of file diff --git a/config/vis/visrc.lua b/config/vis/visrc.lua index ce42ab9..a4a2a14 100644 --- a/config/vis/visrc.lua +++ b/config/vis/visrc.lua @@ -8,6 +8,8 @@ require('plugins/vis-commentary/vis-commentary') -- This hooks vis.events.START so its fine to load it before the default settings require('plugins/vis-modelines/vis-modelines') +require('plugins/suw') + vis.events.subscribe(vis.events.INIT, function() -- Your global configuration options local theme = "default" @@ -31,8 +33,7 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) win:set_syntax("diff") end - local filetype = win.file.name:match(".*%.(.*)") - if filetype == "py" then + if win.syntax == "python" then vis:command("set expand") end end -- cgit v1.2.3