From e3355259bd8ecd56fa4b05dc3931d70bc48572b4 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 5 Feb 2024 10:38:39 +0100 Subject: [PATCH] feat: integrate gum into other git alias Use gum in git branch deletion alias --- git/bin/git-co | 8 ++++---- git/gitconfig | 41 ++++++++++++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/git/bin/git-co b/git/bin/git-co index af5a298..ef553b4 100755 --- a/git/bin/git-co +++ b/git/bin/git-co @@ -357,14 +357,14 @@ verbose_msg "OS : ${OS}" # TODO: Add commit log as preview checkout() { - local gum_filter='gum filter --fuzzy --height=60 --width=0 --limit=1 --header "Select branch"' + local gum_filter='gum filter --fuzzy --height=20 --width=0 --limit=1 --header "Select branch"' local fzf_filter='fzf --select-1 --exit-0 --height=60%' local filter - if hash fzf 2>/dev/null; then - filter="$fzf_filter" - elif hash gum 2>/dev/null; then + if hash gum 2>/dev/null; then filter="$gum_filter" + elif hash fzf 2>/dev/null; then + filter="$fzf_filter" else error_msg "Missing fzf and gum, cannot continue" return 1 diff --git a/git/gitconfig b/git/gitconfig index 93b7319..bc243f0 100644 --- a/git/gitconfig +++ b/git/gitconfig @@ -177,8 +177,6 @@ b = branch ; Show local branches ba = branch --all ; Show all local and remote branches - bd = branch -d ; Delete a merged branch - bdd = branch -D ; Force branch deletion bdr = push origin --delete ; Delete remote branch br = branch -m ; Rename a branch @@ -398,18 +396,39 @@ ; Undo any given number of commits ulc = "!f(){ git reset --soft HEAD~${1}; }; f" + ; Gum / Fuzzy integrations + bd = "!f(){ \ + if [[ -n $1 ]]; then \ + git branch -d "$1"; \ + else \ + local branch=$(git branch | cut -d' ' -f2,3 | awk '{$1=$1;print}' | gum filter --fuzzy --limit=1 --height=20 --header='Delete Branch'); \ + [[ -n $branch ]] && git branch -d "$branch";\ + fi ;\ + }; f" + + bdd = "!f(){ \ + if [[ -n $1 ]]; then \ + git branch -D "$1"; \ + else \ + local branch=$(git branch | cut -d' ' -f2,3 | awk '{$1=$1;print}' | gum filter --fuzzy --limit=1 --height=20 --header='Force Delete Branch'); \ + [[ -n $branch ]] && git branch -D "$branch";\ + fi ;\ + }; f" + ; Apply, pop or drop a specific stash - sw = "!f(){ git stash show --diff-algorithm=patience -B -C --find-copies-harder -p stash@{${1:-0}}; }; f" - sa = "!f(){ git --no-pager stash apply stash@{${1:-0}}; }; f" - sp = "!f(){ git --no-pager stash pop stash@{${1:-0}}; }; f" - ss = "!f(){ git --no-pager stash save $1; }; f" - sd = "!f(){ git --no-pager stash drop stash@{${1:-0}}; }; f" + sw = "!f(){ git stash show --diff-algorithm=patience -B -C --find-copies-harder -p stash@{${1:-0}}; }; f" + sa = "!f(){ git --no-pager stash apply --index stash@{${1:-0}}; }; f" + sp = "!f(){ git --no-pager stash pop --index stash@{${1:-0}}; }; f" + spf = "!f(){ git stash show -p stash@{${1:-0}} | git apply -3 && git stash drop stash@{${1:-0}}; }; f" + sd = "!f(){ git --no-pager stash drop stash@{${1:-0}}; }; f" + ss = "!f(){ git --no-pager stash save $1; }; f" ; manage last stash - swl = "!f(){ git stash show --diff-algorithm=patience -B -C --find-copies-harder -p stash@{$(($(git stash list | wc -l) - 1))}; }; f" - sal = "!f(){ git --no-pager stash apply stash@{$(($(git stash list | wc -l) - 1))}; }; f" - spl = "!f(){ git --no-pager stash pop stash@{$(($(git stash list | wc -l) - 1))}; }; f" - sdl = "!f(){ git --no-pager stash drop stash@{$(($(git stash list | wc -l) - 1))}; }; f" + swl = "!f(){ git stash show --diff-algorithm=patience -B -C --find-copies-harder -p stash@{$(($(git stash list | wc -l) - 1))}; }; f" + sal = "!f(){ git --no-pager stash apply --index stash@{$(($(git stash list | wc -l) - 1))}; }; f" + spl = "!f(){ git --no-pager stash pop --index stash@{$(($(git stash list | wc -l) - 1))}; }; f" + splf = "!f(){ git --no-pager stash show -p stash@{$(($(git stash list | wc -l) - 1))} | git apply -3 && git stash drop stash@{${1:-0}}; }; f" + sdl = "!f(){ git --no-pager stash drop stash@{$(($(git stash list | wc -l) - 1))}; }; f" ; --------- Below here credits to https://github.com/alrra/dotfiles --------- ; Remove the tag with the specified tag name if exists and tag the latest