Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions modules/neovim/init/basic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
lib,
...
}: let
inherit (lib.lists) optional;
inherit (lib.options) mkOption mkEnableOption literalMD;
inherit (lib.strings) optionalString;
inherit (lib.attrsets) optionalAttrs;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Loading