fix: made chmodx escape safe + used vim API

remotes/origin/HEAD
Juliette Lamarche 2022-11-26 21:34:59 -05:00
parent 902335bf12
commit 721d77b549
No known key found for this signature in database
GPG Key ID: 004A3B1CB2774189
1 changed files with 16 additions and 4 deletions

View File

@ -114,11 +114,23 @@ function M.copyFilename() copyOp("filename") end
--------------------------------------------------------------------------------
---Run `chmod +x` on the current file. Requires `chmod`.
---Makes current file executable
function M.chmodx()
local currentFile = expand("%:p")
os.execute("chmod +x '" .. currentFile .. "'")
vim.notify(" Execution permission granted. ")
local filename = vim.fn.expand('%')
local perm = vim.fn.getfperm(filename)
local res = ''
local r
for j = 1, perm:len() do
local char = perm:sub(j, j)
if j % 3 == 1 then
r = char == 'r'
end
if j % 3 == 0 and r then
char = 'x'
end
res = res .. char
end
vim.fn.setfperm(filename, res)
end
---Trash the Current File. Requires `mv`.