Merge branch 'customize' of gitea.hptrow.me:pt/nvchad into customize
This commit is contained in:
commit
c5e5ae4385
@ -1,7 +1,7 @@
|
|||||||
local options = {
|
local options = {
|
||||||
formatters_by_ft = {
|
formatters_by_ft = {
|
||||||
lua = { "stylua" },
|
lua = { "stylua" },
|
||||||
sql = { "pg_format", "sqlfluff" }, -- pg_format first, fallback to sqlfluff
|
sql = { "sql-formatter" },
|
||||||
json = { "jq" },
|
json = { "jq" },
|
||||||
markdown = { "mdformat" },
|
markdown = { "mdformat" },
|
||||||
-- css = { "prettier" },
|
-- css = { "prettier" },
|
||||||
@ -9,15 +9,10 @@ local options = {
|
|||||||
},
|
},
|
||||||
-- no format_on_save (manual-only)
|
-- no format_on_save (manual-only)
|
||||||
formatters = {
|
formatters = {
|
||||||
pg_format = {
|
["sql-formatter"] = {
|
||||||
prepend_args = {
|
command = vim.fn.stdpath("data") .. "/mason/bin/sql-formatter",
|
||||||
"--keyword-case", "2", -- 1 = UPPER, 2 = lower
|
args = { "-l", "postgresql" },
|
||||||
"--function-case", "2", -- 2 = lower
|
stdin = true,
|
||||||
"--spaces", "4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
sqlfluff = {
|
|
||||||
args = { "fix", "--force", "--dialect", "postgres", "-" },
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,3 +61,16 @@ end, { desc = "Wrap selected text in double quotes" })
|
|||||||
|
|
||||||
-- Gitsigns blame current line
|
-- Gitsigns blame current line
|
||||||
vim.keymap.set("n", "<leader>gb", ":Gitsigns blame_line<CR>", { noremap = true, silent = true, desc = "Git blame line" })
|
vim.keymap.set("n", "<leader>gb", ":Gitsigns blame_line<CR>", { noremap = true, silent = true, desc = "Git blame line" })
|
||||||
|
|
||||||
|
-- Disable alt+h and alt+v terminal toggles
|
||||||
|
vim.keymap.del({ "n", "t" }, "<A-h>")
|
||||||
|
vim.keymap.del({ "n", "t" }, "<A-v>")
|
||||||
|
|
||||||
|
-- td: time-track markdown todos (see ~/.local/bin/td and ~/.config/nvim/lua/td.lua)
|
||||||
|
local td = require("td")
|
||||||
|
vim.api.nvim_create_user_command("TdStart", td.start, {})
|
||||||
|
vim.api.nvim_create_user_command("TdStop", td.stop, {})
|
||||||
|
vim.api.nvim_create_user_command("TdReport", td.report, {})
|
||||||
|
vim.keymap.set("n", "<leader>ts", td.start, { desc = "td: start timer on current task" })
|
||||||
|
vim.keymap.set("n", "<leader>tp", td.stop, { desc = "td: stop (pause) timer" })
|
||||||
|
vim.keymap.set("n", "<leader>tr", td.report, { desc = "td: report floating window" })
|
||||||
|
|||||||
@ -63,6 +63,20 @@ return {
|
|||||||
lazy = false
|
lazy = false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- Gitsigns with border configuration
|
||||||
|
{
|
||||||
|
"lewis6991/gitsigns.nvim",
|
||||||
|
opts = {
|
||||||
|
preview_config = {
|
||||||
|
border = "rounded", -- Options: "single", "double", "rounded", "solid", "shadow"
|
||||||
|
style = "minimal",
|
||||||
|
relative = "cursor",
|
||||||
|
row = 0,
|
||||||
|
col = 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
-- Mason (to install formatters like pgformatter/sqlfluff)
|
-- Mason (to install formatters like pgformatter/sqlfluff)
|
||||||
{
|
{
|
||||||
"williamboman/mason.nvim",
|
"williamboman/mason.nvim",
|
||||||
|
|||||||
@ -1,5 +1,20 @@
|
|||||||
local home = os.getenv("HOME") or "~"
|
local home = os.getenv("HOME") or "~"
|
||||||
|
|
||||||
|
local function dir_exists(path)
|
||||||
|
return vim.fn.isdirectory(vim.fn.expand(path)) == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local all_workspaces = {
|
||||||
|
{ name = "journal", path = home .. "/journal" },
|
||||||
|
{ name = "work", path = home .. "/hc_notes" },
|
||||||
|
{ name = "SQL", path = "/mnt/c/Users/ptrowbridge/SQL" },
|
||||||
|
{ name = "pl", path = "/mnt/c/Users/ptrowbridge/plbuild" },
|
||||||
|
}
|
||||||
|
|
||||||
|
local workspaces = vim.tbl_filter(function(w)
|
||||||
|
return dir_exists(w.path)
|
||||||
|
end, all_workspaces)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"epwalsh/obsidian.nvim",
|
"epwalsh/obsidian.nvim",
|
||||||
version = "*",
|
version = "*",
|
||||||
@ -9,24 +24,7 @@ return {
|
|||||||
"nvim-lua/plenary.nvim",
|
"nvim-lua/plenary.nvim",
|
||||||
},
|
},
|
||||||
opts = {
|
opts = {
|
||||||
workspaces = {
|
workspaces = workspaces,
|
||||||
{
|
|
||||||
name = "journal",
|
|
||||||
path = home .. "/journal",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name = "work",
|
|
||||||
path = home .. "/hc_notes",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name = "SQL",
|
|
||||||
path = "/mnt/c/Users/ptrowbridge/SQL",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name = "pl",
|
|
||||||
path = "/mnt/c/Users/ptrowbridge/plbuild",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
104
lua/td.lua
Normal file
104
lua/td.lua
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
local function vault_root()
|
||||||
|
local file = vim.api.nvim_buf_get_name(0)
|
||||||
|
local dir = file ~= "" and vim.fn.fnamemodify(file, ":p:h") or vim.fn.getcwd()
|
||||||
|
local probe = dir
|
||||||
|
while probe ~= "/" and probe ~= "" do
|
||||||
|
if vim.loop.fs_stat(probe .. "/time.csv") or vim.loop.fs_stat(probe .. "/.obsidian") then
|
||||||
|
return probe
|
||||||
|
end
|
||||||
|
local parent = vim.fn.fnamemodify(probe, ":h")
|
||||||
|
if parent == probe then break end
|
||||||
|
probe = parent
|
||||||
|
end
|
||||||
|
return vim.fn.getcwd()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function relpath(abs, base)
|
||||||
|
local a = vim.fn.fnamemodify(abs, ":p")
|
||||||
|
local b = vim.fn.fnamemodify(base, ":p"):gsub("/$", "")
|
||||||
|
if a:sub(1, #b + 1) == b .. "/" then return a:sub(#b + 2) end
|
||||||
|
return a
|
||||||
|
end
|
||||||
|
|
||||||
|
local function run(cmd, cwd, on_done)
|
||||||
|
local stdout, stderr = {}, {}
|
||||||
|
vim.fn.jobstart(cmd, {
|
||||||
|
cwd = cwd,
|
||||||
|
stdout_buffered = true,
|
||||||
|
stderr_buffered = true,
|
||||||
|
on_stdout = function(_, d) for _, l in ipairs(d) do if l ~= "" then stdout[#stdout + 1] = l end end end,
|
||||||
|
on_stderr = function(_, d) for _, l in ipairs(d) do if l ~= "" then stderr[#stderr + 1] = l end end end,
|
||||||
|
on_exit = function(_, code)
|
||||||
|
vim.schedule(function() if on_done then on_done(stdout, stderr, code) end end)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
local function notify(lines, level)
|
||||||
|
if #lines == 0 then return end
|
||||||
|
vim.notify(table.concat(lines, "\n"), level or vim.log.levels.INFO)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function extract_desc(line)
|
||||||
|
return (line:gsub("^%s*%-%s*%[.%]%s*", ""):gsub("%s*%^%S+%s*$", ""):gsub("%s+$", ""))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function ensure_tid_on_line()
|
||||||
|
local line = vim.api.nvim_get_current_line()
|
||||||
|
local tid = line:match("%^(tid%-%S+)")
|
||||||
|
if tid then return tid end
|
||||||
|
if not line:match("^%s*%-%s*%[.%]") then
|
||||||
|
vim.notify("td: not on a todo line (- [ ] ...)", vim.log.levels.WARN)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
tid = os.date("tid-%Y%m%d-%H%M%S")
|
||||||
|
local new = line:gsub("%s+$", "") .. " ^" .. tid
|
||||||
|
vim.api.nvim_set_current_line(new)
|
||||||
|
vim.cmd("silent! write")
|
||||||
|
return tid
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.start()
|
||||||
|
local tid = ensure_tid_on_line()
|
||||||
|
if not tid then return end
|
||||||
|
local cwd = vault_root()
|
||||||
|
local file = relpath(vim.api.nvim_buf_get_name(0), cwd)
|
||||||
|
local desc = extract_desc(vim.api.nvim_get_current_line())
|
||||||
|
run({ "td", "start", tid, "--file", file, "--desc", desc }, cwd, function(out, err)
|
||||||
|
notify(out); notify(err, vim.log.levels.WARN)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.stop()
|
||||||
|
run({ "td", "stop" }, vault_root(), function(out, err)
|
||||||
|
notify(out); notify(err, vim.log.levels.WARN)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.report()
|
||||||
|
run({ "td", "report" }, vault_root(), function(out, err)
|
||||||
|
if #out == 0 then notify(err, vim.log.levels.WARN); return end
|
||||||
|
local buf = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, out)
|
||||||
|
vim.api.nvim_buf_set_option(buf, "modifiable", false)
|
||||||
|
local width = math.min(100, vim.o.columns - 4)
|
||||||
|
local height = math.min(20, #out + 2)
|
||||||
|
vim.api.nvim_open_win(buf, true, {
|
||||||
|
relative = "editor",
|
||||||
|
width = width,
|
||||||
|
height = height,
|
||||||
|
row = math.floor((vim.o.lines - height) / 2),
|
||||||
|
col = math.floor((vim.o.columns - width) / 2),
|
||||||
|
style = "minimal",
|
||||||
|
border = "rounded",
|
||||||
|
title = " td report ",
|
||||||
|
title_pos = "center",
|
||||||
|
})
|
||||||
|
vim.api.nvim_buf_set_keymap(buf, "n", "q", "<cmd>close<cr>", { noremap = true, silent = true })
|
||||||
|
vim.api.nvim_buf_set_keymap(buf, "n", "<Esc>", "<cmd>close<cr>", { noremap = true, silent = true })
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
Loading…
Reference in New Issue
Block a user