-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgit_multi.sh
More file actions
executable file
·76 lines (65 loc) · 1.87 KB
/
git_multi.sh
File metadata and controls
executable file
·76 lines (65 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
# path: /home/klassiker/.local/share/repos/shell/git_multi.sh
# author: klassiker [mrdotx]
# url: https://github.com/mrdotx/shell
# date: 2026-02-17T05:57:23+0100
# config
default="status"
procs=$(($(nproc --all) * 4))
# color variables for interactive shell
tty -s \
&& reset="\033[0m" \
&& bold="\033[1m" \
&& green="\033[32m" \
&& blue="\033[94m" \
&& cyan="\033[96m"
# help
script=$(basename "$0")
help="$script [-h/--help] -- script to execute git command on multiple repositories
Usage:
$script [git option] [path-1] [path-n]
Settings:
[git option] = option like fetch origin or pull (default=$default)
[path] = path to folder with n repositories
Examples:
$script
$script \"fetch origin\" \"$HOME/.local/share/repos\"
$script \"pull\" \"\$HOME/.local/share/repos\" \"/srv/http\""
# helper functions
git_folder() {
folders="$(printf "%s" "${*:-$(pwd)}" \
| sed 's/ /\n/g' \
)"
for folder in $folders; do
find "$folder" -maxdepth 2 -type d -name ".git" \
| sed 's/\/.git//' \
| sort
done
}
command_constructor() {
for folder in $1; do
repo_folder="${folder%/*}"
printf "\"git -P -C %s %s" \
"$folder" "$options"
printf " && printf '%b%b==>%b completed: %bgit%b %s %b%s%b\\\n'\"\n" \
"$bold" "$green" "$reset" "$green" "$reset" "$options" "$cyan" \
"${repo_folder##*/}/${folder##*/}" "$reset"
done
}
case $1 in
-h | --help)
printf "%s\n" "$help"
exit 0
;;
*/*)
options="$default"
;;
*)
options="${1:-$default}"
[ $# -ge 1 ] \
&& shift
esac
printf "%b%b::%b %bexecute git operations:%b\n" \
"$bold" "$blue" "$reset" "$bold" "$reset"
command_constructor "$(git_folder "$@")" \
| xargs -P"$procs" -I{} sh -c '{}'