aboutsummaryrefslogtreecommitdiff
path: root/config/vis/plugins
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2018-06-26 16:22:13 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2018-06-26 16:22:13 +0200
commit1a9f87f584d37ccea3ea84b788a4eb36321ccbb9 (patch)
treee0e311c41e5fc11a4a34cf0e1ecede4cae3e2dd0 /config/vis/plugins
parent4dc775365f50dd1e7d99ab81cd983c47c4feee4f (diff)
downloaddotfiles-1a9f87f584d37ccea3ea84b788a4eb36321ccbb9.tar.gz
dotfiles-1a9f87f584d37ccea3ea84b788a4eb36321ccbb9.zip
[vis] add suw plugin to write as root
Diffstat (limited to 'config/vis/plugins')
-rw-r--r--config/vis/plugins/suw.lua32
1 files changed, 32 insertions, 0 deletions
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