Update gitconfig: git_pushmulti
This commit is contained in:
parent
a6e2aa616c
commit
00e4707b25
@ -22,6 +22,7 @@
|
|||||||
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
|
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
|
||||||
today = log --since=midnight --author='Roberto Bonvallet' --oneline
|
today = log --since=midnight --author='Roberto Bonvallet' --oneline
|
||||||
pushall = !git remote | xargs -L1 git push --all
|
pushall = !git remote | xargs -L1 git push --all
|
||||||
|
pushmulti = !git-pushmulti
|
||||||
s = status
|
s = status
|
||||||
a = add --all
|
a = add --all
|
||||||
cm = commit -m
|
cm = commit -m
|
||||||
|
53
dot_local/bin/executable_git-pushmulti
Normal file
53
dot_local/bin/executable_git-pushmulti
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# --------------------------
|
||||||
|
# 擷取 remote list
|
||||||
|
# --------------------------
|
||||||
|
extract_list() {
|
||||||
|
local input="$1"
|
||||||
|
input="${input//[()]/}" # 去掉括號
|
||||||
|
IFS=',' read -ra result <<< "$input"
|
||||||
|
echo "${result[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# --------------------------
|
||||||
|
# 主邏輯
|
||||||
|
# --------------------------
|
||||||
|
|
||||||
|
# 預設值
|
||||||
|
remotes=()
|
||||||
|
branches=()
|
||||||
|
|
||||||
|
# 取出第一個參數:應該是 (remote1,remote2)
|
||||||
|
if [[ "$1" =~ ^\(.+\)$ ]]; then
|
||||||
|
remotes=($(extract_list "$1"))
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
echo "❌ 請使用 (remote1,remote2) 的格式作為第一個參數"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 剩下的參數是 branches(若為空就抓當前 branch)
|
||||||
|
if [[ $# -gt 0 ]]; then
|
||||||
|
branches=("$@")
|
||||||
|
else
|
||||||
|
current_branch=$(git symbolic-ref --short HEAD 2>/dev/null)
|
||||||
|
if [[ -z "$current_branch" ]]; then
|
||||||
|
echo "❌ 無法偵測目前所在 branch,請指定"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
branches=("$current_branch")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --------------------------
|
||||||
|
# 執行 git push
|
||||||
|
# --------------------------
|
||||||
|
for remote in "${remotes[@]}"; do
|
||||||
|
for branch in "${branches[@]}"; do
|
||||||
|
echo "🚀 Pushing to '$remote' (branch: '$branch')..."
|
||||||
|
git push "$remote" "$branch"
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo "❌ Push to '$remote' 失敗"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
14
dot_zshrc
14
dot_zshrc
@ -191,3 +191,17 @@ if ! alias imgcat &>/dev/null && ! functions imgcat &>/dev/null && command -v ma
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
zinit light mass8326/zsh-chezmoi
|
zinit light mass8326/zsh-chezmoi
|
||||||
|
|
||||||
|
# 自動補上 noglob 並禁用 Zsh 的 globbing 解析
|
||||||
|
function git_pushmulti() {
|
||||||
|
# 手動處理方括號或括號內容,並進行推送
|
||||||
|
local remotes="$1"
|
||||||
|
local branches="$2"
|
||||||
|
remotes="${remotes//\[/\"[\"}"
|
||||||
|
remotes="${remotes//\]/\"]\"}"
|
||||||
|
branches="${branches//\[/\"[\"}"
|
||||||
|
branches="${branches//\]/\"]\"}"
|
||||||
|
|
||||||
|
# 執行 git pushmulti
|
||||||
|
noglob git pushmulti "$remotes" "$branches"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user