From 3cd95263915f098df7696865420950c1c0f342c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?deniz=20g=C3=B6k=C3=A7in?= <33603535+dgokcin@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:38:37 +0100 Subject: [PATCH] refactor: streamline git aliases for efficiency (#135) - Consolidate similar git commands into single aliases - Remove redundant comments and streamline command syntax - Enhance readability and maintainability of git configuration --- base.gitconfig | 53 +++++++++++------------------------- nvim/lua/config/autocmds.lua | 8 ++++++ 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/base.gitconfig b/base.gitconfig index e0e66a67..255e4bbc 100644 --- a/base.gitconfig +++ b/base.gitconfig @@ -3,14 +3,14 @@ name = Deniz Gökçin [init] - defaultBranch = main + defaultBranch = main [merge] ff = false tool = intellij [mergetool] - keepBackup = false + keepBackup = false # Use intellij as git mergetool [mergetool "intellij"] @@ -36,10 +36,10 @@ whitespace = cr-at-eol [pull] - rebase = true + rebase = true [push] - autoSetupRemote = true + autoSetupRemote = true [alias] # Add @@ -140,18 +140,18 @@ # Get the parent branch of the current branch parent = "!f() { \ - branch=$(git symbolic-ref --short HEAD); \ - if [[ $branch =~ ^(main|master|develop)$ ]]; then \ - echo \"You're already on a main branch: $branch\"; \ - else \ - parent_branch=$(git for-each-ref --format='%(refname:short)' refs/heads/ | grep -E '^(main|master|develop)' | head -n 1); \ - if [ -z \"$parent_branch\" ]; then \ - echo \"No common parent branch (main/master/develop) found.\"; \ - else \ - echo \"$parent_branch\"; \ - fi; \ - fi; \ - }; f" + branch=$(git symbolic-ref --short HEAD); \ + if [[ $branch =~ ^(main|master|develop)$ ]]; then \ + echo \"You're already on a main branch: $branch\"; \ + else \ + parent_branch=$(git for-each-ref --format='%(refname:short)' refs/heads/ | grep -E '^(main|master|develop)' | head -n 1); \ + if [ -z \"$parent_branch\" ]; then \ + echo \"No common parent branch (main/master/develop) found.\"; \ + else \ + echo \"$parent_branch\"; \ + fi; \ + fi; \ + }; f" # List contributors with number of commits contributors = shortlog --summary --numbered @@ -189,28 +189,7 @@ # Fixup with fzf fixup = "!git log -n 50 --pretty=format:'%h %s' --no-merges | fzf | cut -c -7 | xargs -o git commit --fixup" - # Delete all local branches except the excluded ones - prune = "!f() { \ - exclude_branches=(main master $@); \ - branches_to_delete=$(git branch | grep -v -E \"($(IFS='|'; echo "${exclude_branches[*]}"))\"); \ - if [ -z \"$branches_to_delete\" ]; then \ - echo \"No branches to delete.\"; \ - return 0; \ - fi; \ - echo \"Branches to delete:\"; \ - echo \"$branches_to_delete\"; \ - read -p \"Are you sure you want to delete these branches? (y/n) \" -n 1 -r; \ - echo; \ - if [[ $REPLY =~ ^[Yy]$ ]]; then \ - echo \"$branches_to_delete\" | xargs git branch -D; \ - echo \"Branches deleted.\"; \ - else \ - echo \"Operation cancelled.\"; \ - fi; \ - }; f" - [help] - # Automatically correct and execute mistyped commands autocorrect = 1 diff --git a/nvim/lua/config/autocmds.lua b/nvim/lua/config/autocmds.lua index 830c7615..f26aa397 100644 --- a/nvim/lua/config/autocmds.lua +++ b/nvim/lua/config/autocmds.lua @@ -31,4 +31,12 @@ vim.api.nvim_create_autocmd("FileType", { vim.bo[ev.buf].commentstring = "# %s" end, pattern = { "terraform", "hcl", "tf" }, +}) + +-- auto-recognize gitconfig filetypes +vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, { + pattern = { "*.gitconfig", ".gitconfig", "gitconfig", ".gitconfig.*" }, + callback = function() + vim.opt_local.filetype = "gitconfig" + end, }) \ No newline at end of file