From 2b1d1249dfd3bf4c32ebf203f2b4509c63efe096 Mon Sep 17 00:00:00 2001 From: Squibid Date: Fri, 29 Mar 2024 23:28:36 -0400 Subject: make x toggle executable status --- lua/conf/binds.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lua/conf/binds.lua') diff --git a/lua/conf/binds.lua b/lua/conf/binds.lua index d76cb8a..4549553 100644 --- a/lua/conf/binds.lua +++ b/lua/conf/binds.lua @@ -31,7 +31,21 @@ map('n', 'N', 'Nzzzv') map('n', '', 'zz') -- half page jumping map('n', '', 'zz') -map('n', 'x', '!chmod +x "%"') -- execute order 111 +map('n', 'x', function() -- execute order 111 + local fn = vim.fn.expand("%:p") + if vim.fn.getftype(fn) == "file" then + local perm = vim.fn.getfperm(fn) + if string.match(perm, "x", 3) then + vim.notify("Removed executable flags", vim.log.levels.INFO, { title = misc.appid }) + vim.fn.setfperm(fn, string.sub(fn, 1, 2).."-"..string.sub(fn, 4, 5).."-"..string.sub(fn, 7, 8).."-") + else + vim.notify("Add executable flags", vim.log.levels.INFO, { title = misc.appid }) + vim.fn.setfperm(fn, string.sub(fn, 1, 2).."x"..string.sub(fn, 4, 5).."x"..string.sub(fn, 7, 8).."x") + end + else + vim.notify("File doesn't exist", vim.log.levels.INFO, { title = misc.appid }) + end +end) -- add some keybinds to the file view (netrw) a.nvim_create_autocmd('FileType', { -- cgit v1.2.1