Skip to content

Commit

Permalink
feat: integrate gum into other git alias
Browse files Browse the repository at this point in the history
Use gum in git branch deletion alias
  • Loading branch information
mike325 committed Feb 5, 2024
1 parent 12d5e9b commit e335525
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
8 changes: 4 additions & 4 deletions git/bin/git-co
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 30 additions & 11 deletions git/gitconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e335525

Please sign in to comment.