我正在尝试为 git 别名编写一个 bash 脚本,以自动化某些事情。
我已经在 repl.it 中编写了脚本,并且它可以正常工作。但是,当我将脚本放入我的 .gitconfig 并将其缩减为一行时,我现在遇到了语法错误。
-c: line 0: syntax error near unexpected token `then'
这显然根本没有帮助,因为一切都在一条线上。
这是我的 git config 中存在的一行脚本
markaswip = "!f(){ fullBranchName='jm/branch/name'; IFS='/' read -r -a array <<< $fullBranchName; hasBranch=0; for element in "${array[@]}" do if [ "$element" = $"wip" ]; then hasBranch=1; fi; done; if [ $hasBranch = 1 ]; then echo "Has WIP tag already"; else appendedString=$(printf '%s/' "${newArray[@]}"); output=${appendedString%?}; echo $output; git branch -m ${commitmessage}; fi; }; f"
在这里展开
f() {
fullBranchName='test/branch/name';
IFS='/' read -r -a array <<< $fullBranchName
hasBranch=0;
for element in "${array[@]}"
do
if [ "$element" = $"wip" ];
then
hasBranch=1;
fi;
done;
if [ $hasBranch = 1 ];
then
echo "Has WIP tag already";
else
newArray=( "${array[@]:0:1}" "wip" "${array[@]:1}" );
appendedString=$(printf '%s/' "${newArray[@]}")
#printf '%s/' "${newArray[@]}"
output=${appendedString%?}
echo $output;
#git branch -m ${commitmessage};
fi;
}
f;