-
Notifications
You must be signed in to change notification settings - Fork 12
/
.nvim.lua
36 lines (31 loc) · 1.22 KB
/
.nvim.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- to run this file as a local nvim config see `help trust`
if (vim.fn.exists "$TMUX" == 1) and (vim.fn.executable "chezmoi" > 0) then
vim.api.nvim_create_user_command("ChezmoiApply", function(arg)
local function command(file)
vim.system({ "tmux", "display-popup", "-E", "chezmoi", "apply", file or nil }, { text = true })
end
local filename = vim.fn.expand "%"
if vim.fn.fnamemodify(filename, ":."):match "^%." then
-- only execute command without filename
-- ignore files starting with `.`
command()
return
end
if arg.bang then
local chezmoi_file = vim.fn.systemlist({ "chezmoi", "target-path", filename })[1]
command(chezmoi_file)
else
command()
end
end, { bang = true })
vim.api.nvim_create_autocmd("BufWritePost", {
group = vim.api.nvim_create_augroup("chezmoi-nvim-lua", { clear = true }),
callback = function(info)
if vim.fn.fnamemodify(info.file, ":."):match "^%." then
-- ignore files starting with `.`
return
end
vim.cmd.ChezmoiApply { bang = true }
end,
})
end