feat: add git branch clean up function ✨
This commit is contained in:
parent
19132a127d
commit
d3e1fbb85d
3 changed files with 25 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
|||
enable = true;
|
||||
shellAliases = {
|
||||
cdtmp = "cd $(mktemp -d)";
|
||||
gclean = "git cleanup-branches";
|
||||
theme = "bash ~/dotfiles/scripts/theme.sh";
|
||||
music = "mpv --no-video --log-file=~/music_history.log \"$(find $HOME/Music/ -type f \\( -name '*.mp3' -o -name '*.wav' -o -name '*.flac' -o -name '*.m4a' -o -name '*.ogg' \\) | fzf)\"";
|
||||
weather = "curl wttr.in/?T";
|
||||
|
|
|
|||
|
|
@ -74,6 +74,9 @@
|
|||
core = {
|
||||
editor = "nvim";
|
||||
};
|
||||
alias = {
|
||||
"cleanup-branches" = "!bash ~/dotfiles/scripts/git-cleanup-branches.sh";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
21
scripts/git-cleanup-branches.sh
Executable file
21
scripts/git-cleanup-branches.sh
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
git rev-parse --git-dir >/dev/null 2>&1 || { echo "Not a git repository." >&2; exit 1; }
|
||||
|
||||
default_branch="main"
|
||||
git rev-parse --verify refs/heads/main &>/dev/null || default_branch="master"
|
||||
|
||||
git branch --merged "$default_branch" \
|
||||
| grep -Fv "$default_branch" \
|
||||
| grep -vF '*' \
|
||||
| grep -vF '+' \
|
||||
| xargs git branch -d \
|
||||
&& git fetch \
|
||||
&& git remote prune origin \
|
||||
&& git branch -v \
|
||||
| grep -F '[gone]' \
|
||||
| grep -vF '*' \
|
||||
| grep -vF '+' \
|
||||
| awk '{print $1}' \
|
||||
| xargs git branch -D
|
||||
Loading…
Add table
Add a link
Reference in a new issue