From af71fb6bcabca53a1cfcdef5ad242ea27cb406c7 Mon Sep 17 00:00:00 2001 From: Simon Gruber Date: Mon, 9 Dec 2024 11:01:44 +0100 Subject: [PATCH] Added gitconfig --- .gitconfig | 19 ++++++++++++++++ .gitscripts/git-branches.sh | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 .gitconfig create mode 100644 .gitscripts/git-branches.sh diff --git a/.gitconfig b/.gitconfig new file mode 100644 index 0000000..26cfbd0 --- /dev/null +++ b/.gitconfig @@ -0,0 +1,19 @@ +[user] + name = Simon Gruber +[fetch] + prune = true +[http] + sslbackend = openssl +[core] + autocrlf = true + excludesfile = D:\\Users\\Simon.Gruber\\Documents\\gitignore_global.txt +[push] + autoSetupRemote = true +[init] + defaultbranch = main +[advice] + skippedCherryPicks = false +[pull] + ff = only +[alias] + branches = !sh scripts/git-branches \ No newline at end of file diff --git a/.gitscripts/git-branches.sh b/.gitscripts/git-branches.sh new file mode 100644 index 0000000..5f2bdc6 --- /dev/null +++ b/.gitscripts/git-branches.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +usage() { + echo "Usage: git branches [-f FILTER] ACTION" + echo " -f FILTER Optional branch name filter (default: '*')" + echo " ACTION Command to execute for each branch" + echo " The current branch name is available via variable 'b' or 'branch'" + echo "" + echo "Example:" + echo " git branches -f 'feature/*' 'echo Processing branch: \$b'" + echo " git branches 'git push origin \$branch'" +} + +# Default filter +filter='*' + +# Parse arguments +while [ $# -gt 0 ]; do + case "$1" in + -f) + filter="*$2*" + shift 2 + ;; + -h|--help) + usage + exit 0 + ;; + *) + action="$1" + shift + break + ;; + esac +done + +if [ -z "$action" ]; then + echo "No action provided" + echo + usage + exit 1 +fi + +git branch --list "${filter}" --format='%(refname:short)' | while read -r branch; do + b="$branch" eval "$action" +done \ No newline at end of file