From 38e999bd6a62b6f5424045151022b0d8f32e6583 Mon Sep 17 00:00:00 2001 From: Gabriel Santos Date: Sun, 1 Nov 2026 07:23:44 -0300 Subject: [PATCH] basic: add autoMakeExecutable Add an option to automatically mark files with a shebang as executable on save. --- modules/neovim/init/basic.nix | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/modules/neovim/init/basic.nix b/modules/neovim/init/basic.nix index 85c07a530..7afdbfcc0 100644 --- a/modules/neovim/init/basic.nix +++ b/modules/neovim/init/basic.nix @@ -3,6 +3,7 @@ lib, ... }: let + inherit (lib.lists) optional; inherit (lib.options) mkOption mkEnableOption literalMD; inherit (lib.strings) optionalString; inherit (lib.attrsets) optionalAttrs; @@ -76,6 +77,10 @@ in { description = "Path to the directory in which undo history will be stored"; }; }; + + autoMakeExecutable = { + enable = mkEnableOption "Automatically make files with a shebang executable on save"; + }; }; # Alias vim.options as vim.opts. @@ -132,6 +137,24 @@ in { }) ]); + autocmds = optional cfg.autoMakeExecutable.enable { + event = ["BufWritePost"]; + desc = "Automatically make files with a shebang executable on save"; + callback = mkLuaInline '' + function(args) + local first_line = vim.api.nvim_buf_get_lines(args.buf, 0, 1, false)[1] or "" + + if first_line:match("^#!") then + local file = vim.api.nvim_buf_get_name(args.buf) + + if file ~= "" then + vim.fn.system({"chmod", "+x", file}) + end + end + end + ''; + }; + # Options that are more difficult to set through 'vim.options'. Namely, appending values # to pre-set Neovim options. Fear not, though as the Lua DAG is still as powerful as it # could be.