feat: blamer;

refactor: tab sizes;
feat: hyprlang;
refactor: git add/git restore binds
This commit is contained in:
2025-10-05 15:36:56 +03:00
parent 986512f648
commit 032634fc91
3 changed files with 70 additions and 25 deletions

View File

@@ -48,21 +48,44 @@ local function toggle_terminal()
require("nvchad.term").toggle { pos = "sp", id = "htoggleTerm" }
end
local function toggle_git_add()
-- Git add current file
local function git_add_current_file()
local filepath = vim.fn.expand("%:p") -- Get the full path of the current file
local handle = io.popen("git ls-files --cached --error-unmatch " .. filepath .. " 2>/dev/null") -- Check if the file is staged
local result = handle:read("*a")
handle:close()
local command = "git add " .. vim.fn.shellescape(filepath)
local output = vim.fn.system(command)
if result ~= "" then
os.execute("git reset " .. filepath) -- Unstage the file if it's already staged
print("Unstaged: " .. filepath)
if vim.v.shell_error ~= 0 then
print("Error adding file: " .. output)
else
os.execute("git add " .. filepath) -- Stage the file if it's not staged
print("Staged: " .. filepath)
print("Added: " .. filepath)
end
end
-- Git unstage (reset) current file
local function git_unstage_current_file()
local filepath = vim.fn.expand("%:p") -- Get the full path of the current file
local command = "git reset HEAD -- " .. vim.fn.shellescape(filepath)
local output = vim.fn.system(command)
if vim.v.shell_error ~= 0 then
print("Error unstaging file: " .. output)
else
print("Unstaged: " .. filepath)
end
end
-- Alternative unstage using restore (Git 2.23+)
local function git_unstage_current_file_restore()
local filepath = vim.fn.expand("%:p") -- Get the full path of the current file
local command = "git restore --staged " .. vim.fn.shellescape(filepath)
local output = vim.fn.system(command)
if vim.v.shell_error ~= 0 then
print("Error unstaging file: " .. output)
else
print("Unstaged: " .. filepath)
end
end
map({ "n", "t" }, "<A-b>", toggle_terminal, { desc = "terminal toggleable horizontal term" })
map({ "n", "t" }, "<C-`>", toggle_terminal, { desc = "terminal toggleable horizontal term" })
@@ -103,7 +126,9 @@ vim.keymap.set("n", "<leader>ft", '<cmd>TodoTelescope<cr>', { desc = "Telescope
vim.keymap.set("n", "<leader>tr", '<cmd>NvimTreeRefresh<cr>', { desc = "Nvimtree Refresh" })
-- toggle git add current file
vim.keymap.set("n", "<leader>ga", toggle_git_add, { desc = "Toggle git add for current file" })
vim.keymap.set("n", "<leader>ga", git_add_current_file, { desc = "Git add file" })
vim.keymap.set("n", "<leader>gd", git_unstage_current_file, { desc = "Git unstage file" })
vim.keymap.set("n", "<leader>gr", git_unstage_current_file_restore, { desc = "Git unstage file (restore)" })
-- nvimtree open file without focusing
vim.keymap.set("n", "T",

View File

@@ -17,7 +17,27 @@ local enable_providers = {
-- disable wrap
vim.o.wrap = false
-- amount of tabs
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.shiftwidth = 4
-- disable auto comment
vim.opt_local.formatoptions:remove("r")
vim.g.lua_snippets_path = "~/.config/nvim/lua/lua_snippets"
-- enable blamer
vim.g.blamer_enabled = true
-- Hyprlang LSP
vim.api.nvim_create_autocmd({'BufEnter', 'BufWinEnter'}, {
pattern = {"*.hl", "hypr*.conf"},
callback = function()
vim.lsp.start {
name = "hyprlang",
cmd = {"hyprls"},
root_dir = vim.fn.getcwd(),
}
end
})