Skip to content

Instantly share code, notes, and snippets.

@abaez
Created May 21, 2018 15:16
Show Gist options
  • Save abaez/191397143c72ab7622e1812f6d887336 to your computer and use it in GitHub Desktop.
Save abaez/191397143c72ab7622e1812f6d887336 to your computer and use it in GitHub Desktop.
A sudo write for vis
--- 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment