neovim: rewrite config
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
local u = require("daniil.utils")
|
||||
|
||||
local git = {}
|
||||
|
||||
--- @return string commit_hash
|
||||
function git.get_commit_hash_for_current_line()
|
||||
local fullpath = vim.api.nvim_buf_get_name(0)
|
||||
local cwd = vim.loop.cwd()
|
||||
local relative_path = string.gsub(fullpath, cwd .. "/", "")
|
||||
|
||||
local line = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
|
||||
local f = io.popen("git blame -L " .. line .. ",+1 " .. relative_path, "r")
|
||||
local data = f:read("*a")
|
||||
f:close()
|
||||
|
||||
local commit_hash = vim.split(data, " ")[1]
|
||||
|
||||
return commit_hash
|
||||
end
|
||||
|
||||
--- @return string git_remote_url
|
||||
function git.get_remote_url()
|
||||
local f = io.popen("git remote get-url origin", "r")
|
||||
local remote_url = f:read("*l")
|
||||
f:close()
|
||||
|
||||
if string.sub(remote_url, 0, 4) == "git@" then
|
||||
remote_url = string.gsub(remote_url, "git@", "")
|
||||
remote_url = string.gsub(remote_url, ".git", "")
|
||||
remote_url = string.gsub(remote_url, ":", "/")
|
||||
end
|
||||
|
||||
if string.sub(remote_url, 0, 5) ~= "https" then
|
||||
remote_url = "https://" .. remote_url
|
||||
end
|
||||
|
||||
return remote_url
|
||||
end
|
||||
|
||||
function git.open_commit_on_github()
|
||||
local commit_hash = git.get_commit_hash_for_current_line()
|
||||
local remote_url = git.get_remote_url()
|
||||
|
||||
if commit_hash == "00000000" then
|
||||
print("Not committed yet")
|
||||
return
|
||||
end
|
||||
|
||||
local commit_url = remote_url .. "/commit/" .. commit_hash
|
||||
|
||||
u.open_url_in_browser(commit_url)
|
||||
end
|
||||
|
||||
return git
|
||||
1
neovim/.config/nvim/lua/daniil/init.lua
Normal file
1
neovim/.config/nvim/lua/daniil/init.lua
Normal file
@@ -0,0 +1 @@
|
||||
print "fuck"
|
||||
@@ -1,25 +0,0 @@
|
||||
require("Comment").setup({
|
||||
pre_hook = function(ctx)
|
||||
-- Only calculate commentstring for tsx filetypes
|
||||
if vim.bo.filetype == "typescriptreact" or vim.bo.filetype == "javascriptreact" then
|
||||
local U = require("Comment.utils")
|
||||
|
||||
-- Detemine whether to use linewise or blockwise commentstring
|
||||
-- local type = ctx.ctype == U.ctype.line and "__default" or "__multiline"
|
||||
local type = "__default"
|
||||
|
||||
-- Determine the location where to calculate commentstring from
|
||||
local location = nil
|
||||
if ctx.ctype == U.ctype.block then
|
||||
location = require("ts_context_commentstring.utils").get_cursor_location()
|
||||
elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then
|
||||
location = require("ts_context_commentstring.utils").get_visual_start_location()
|
||||
end
|
||||
|
||||
return require("ts_context_commentstring.internal").calculate_commentstring({
|
||||
key = type,
|
||||
location = location,
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
@@ -1,43 +0,0 @@
|
||||
local a = require("gitsigns.actions")
|
||||
|
||||
require("gitsigns").setup({
|
||||
signcolumn = true,
|
||||
attach_to_untracked = false,
|
||||
current_line_blame = true,
|
||||
current_line_blame_opts = {
|
||||
delay = 1000,
|
||||
},
|
||||
current_line_blame_formatter_opts = {
|
||||
relative_time = true,
|
||||
},
|
||||
on_attach = function(bufnr)
|
||||
vim.keymap.set("n", "<leader>gs", function()
|
||||
a.stage_hunk()
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>gu", function()
|
||||
a.undo_stage_hunk()
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>gr", function()
|
||||
a.reset_hunk()
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>gp", function()
|
||||
a.preview_hunk()
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>gn", function()
|
||||
a.next_hunk()
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>gN", function()
|
||||
a.prev_hunk()
|
||||
end)
|
||||
|
||||
vim.keymap.set("v", "gs", function()
|
||||
a.stage_hunk()
|
||||
end)
|
||||
vim.keymap.set("v", "gu", function()
|
||||
a.undo_stage_hunk()
|
||||
end)
|
||||
vim.keymap.set("v", "gr", function()
|
||||
a.reset_hunk()
|
||||
end)
|
||||
end,
|
||||
})
|
||||
@@ -1,34 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.find_tab = function()
|
||||
local tabpages = vim.api.nvim_list_tabpages()
|
||||
local tabs = {}
|
||||
for _, tabnr in ipairs(tabpages) do
|
||||
local winnr = vim.api.nvim_tabpage_get_win(tabnr)
|
||||
local bufnr = vim.api.nvim_win_get_buf(winnr)
|
||||
|
||||
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||
local root = vim.loop.cwd()
|
||||
local relative_path = string.gsub(bufname, root .. "/", "")
|
||||
|
||||
table.insert(tabs, {
|
||||
bufname = relative_path,
|
||||
tabnr = tabnr,
|
||||
})
|
||||
end
|
||||
|
||||
vim.ui.select(tabs, {
|
||||
prompt = "Choose a tab: ",
|
||||
format_item = function(item)
|
||||
return item.tabnr .. " - " .. item.bufname
|
||||
end,
|
||||
}, function(item)
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
|
||||
vim.api.nvim_set_current_tabpage(item.tabnr)
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,103 +0,0 @@
|
||||
local M = {}
|
||||
|
||||
M.yank = function(message)
|
||||
vim.cmd(":!echo -n '" .. message .. "' | wl-copy")
|
||||
end
|
||||
|
||||
--- @param diagnostics list
|
||||
--- @param prompt string
|
||||
--- @return string
|
||||
M.select_diagnostic = function(diagnostics, prompt)
|
||||
if #diagnostics == 0 then
|
||||
return ""
|
||||
end
|
||||
|
||||
local message = ""
|
||||
|
||||
if #diagnostics == 1 then
|
||||
message = diagnostics[1].message
|
||||
else
|
||||
local d = {}
|
||||
for _, diagnostic in ipairs(diagnostics) do
|
||||
table.insert(d, diagnostic.message)
|
||||
end
|
||||
|
||||
vim.ui.select(d, { prompt = prompt }, function(item)
|
||||
message = item
|
||||
end)
|
||||
end
|
||||
|
||||
return message
|
||||
end
|
||||
|
||||
M.copy_diagnostic_message = function()
|
||||
local diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
|
||||
|
||||
local message = M.select_diagnostic(diagnostics, "Pick a diagnostic to yank")
|
||||
|
||||
M.yank(message)
|
||||
|
||||
print("Diagnostic message was yanked")
|
||||
end
|
||||
|
||||
M.open_url_in_browser = function(url)
|
||||
local _url = string.format('"%s"', url)
|
||||
|
||||
vim.cmd(":!exec xdg-open " .. _url)
|
||||
end
|
||||
|
||||
function M.lsp_format(bufnr)
|
||||
bufnr = bufnr or 0
|
||||
|
||||
vim.lsp.buf.format({
|
||||
filter = function(client)
|
||||
if client.name == "tsserver" then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end,
|
||||
bufnr = bufnr,
|
||||
})
|
||||
end
|
||||
|
||||
function M.open_unsaved_buffers()
|
||||
local buffers = vim.api.nvim_list_bufs()
|
||||
local unsaved_buffers = {}
|
||||
|
||||
local og_bufnr = vim.api.nvim_get_current_buf()
|
||||
|
||||
for _, bufnr in ipairs(buffers) do
|
||||
local is_saved = vim.api.nvim_buf_get_option(bufnr, "modified")
|
||||
|
||||
if is_saved and bufnr ~= og_bufnr then
|
||||
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||
|
||||
table.insert(unsaved_buffers, bufnr)
|
||||
|
||||
vim.cmd("tabnew " .. bufname)
|
||||
end
|
||||
end
|
||||
|
||||
if #unsaved_buffers > 0 then
|
||||
vim.notify("Opened " .. #unsaved_buffers .. " unsaved buffers")
|
||||
end
|
||||
end
|
||||
|
||||
function M.toggle_qflist()
|
||||
if vim.bo.ft == "qf" then
|
||||
vim.cmd(":cclose")
|
||||
else
|
||||
vim.cmd(":copen")
|
||||
end
|
||||
end
|
||||
|
||||
function M.toggle_locationlist()
|
||||
if vim.bo.ft == "qf" then
|
||||
vim.cmd(":lclose")
|
||||
else
|
||||
vim.cmd(":lopen")
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user