.config/nvim/lua/config/commands.lua

Mon, 15 Jul 2024 13:22:56 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 15 Jul 2024 13:22:56 -0500
changeset 1176
1cb4636d6d36
parent 1157
a237720efee9
permissions
-rw-r--r--

Fix for no-nerdfonts experience

1078
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
1 local command = vim.api.nvim_create_user_command
1095
226221dc1d6b Simplify command aliases
Meredith Howard <mhoward@roomag.org>
parents: 1080
diff changeset
2 local cmd, fn = vim.cmd, vim.fn
1156
0a7162df160d pull out last_modified_days
Meredith Howard <mhoward@roomag.org>
parents: 1155
diff changeset
3 local util = require("config.util")
1078
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
4
1156
0a7162df160d pull out last_modified_days
Meredith Howard <mhoward@roomag.org>
parents: 1155
diff changeset
5 util.calias({
1155
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
6 -- replace default:
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
7 grep = "Grep",
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
8
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
9 -- typos:
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
10 Q = "q",
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
11 Qa = "qa",
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
12 W = "w",
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
13 gcd = "Gcd",
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
14 hgcd = "Hgcd",
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
15
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
16 -- Make the ! versions default to stay in one window + buffer:
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
17 doc = "ViewDoc!",
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
18 help = "ViewDocHelp!",
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
19 man = "ViewDocMan!",
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
20 perldoc = "ViewDocPerl!",
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
21 })
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
22
1078
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
23 command("Hgcd", function()
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
24 local root = fn.systemlist("hg root 2>/dev/null")[1]
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
25 if vim.v.shell_error == 0 then
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
26 cmd.cd(root)
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
27 end
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
28 end, {})
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
29
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
30 command("Gcd", function()
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
31 local root = fn.systemlist("git rev-parse --show-toplevel 2>/dev/null")[1]
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
32 if vim.v.shell_error == 0 then
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
33 cmd.cd(root)
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
34 end
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
35 end, {})
aa4c1aa529a5 Start porting custom commands to lua
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
36
1079
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
37 command("Grep", function(ctx)
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
38 local pattern = ctx.fargs[1] or fn.expand("<cword>")
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
39 local grepcmd = table.concat({
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
40 vim.o.grepprg,
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
41 fn.shellescape(pattern),
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
42 table.concat(vim.list_slice(ctx.fargs, 2, #ctx.fargs), " "),
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
43 }, " ")
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
44
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
45 fn.setqflist({}, " ", { title = grepcmd, lines = fn.systemlist(grepcmd) })
1080
83c9f8460bde continue to confuse the verymagic options
Meredith Howard <mhoward@roomag.org>
parents: 1079
diff changeset
46 fn.setreg("/", [[\v]] .. pattern)
1079
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
47 cmd.copen()
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
48 cmd.cfirst()
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
49 end, { nargs = "*", complete = "file" })
b59861305252 port :Grep to lua
Meredith Howard <mhoward@roomag.org>
parents: 1078
diff changeset
50
1155
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
51 -- Remove buffers for files that are gone, old, or netrw dirs
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
52 command("PruneSession", function()
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
53 local bufs = vim.api.nvim_list_bufs()
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
54 for _, bufnr in ipairs(bufs) do
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
55 local name = vim.api.nvim_buf_get_name(bufnr)
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
56 if name then
1157
a237720efee9 Convert backup/undofile pruning to lua
Meredith Howard <mhoward@roomag.org>
parents: 1156
diff changeset
57 local type = fn.getftype(name)
1155
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
58 if type == "" or type == "dir"
1156
0a7162df160d pull out last_modified_days
Meredith Howard <mhoward@roomag.org>
parents: 1155
diff changeset
59 or util.last_modified_days(name) > 30
1155
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
60 then
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
61 vim.print("pruned: " .. name)
1157
a237720efee9 Convert backup/undofile pruning to lua
Meredith Howard <mhoward@roomag.org>
parents: 1156
diff changeset
62 cmd.bwipeout(bufnr)
1155
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
63 end
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
64 end
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
65 end
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
66 if not vim.api.nvim_buf_get_name(0) then
1157
a237720efee9 Convert backup/undofile pruning to lua
Meredith Howard <mhoward@roomag.org>
parents: 1156
diff changeset
67 cmd.bprev()
1155
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
68 end
fcec334dfe7a luafy PruneSession
Meredith Howard <mhoward@roomag.org>
parents: 1095
diff changeset
69 end, {})

mercurial