我是 zsh 和 git 的新手,我正在尝试编写一个函数来粘贴在我的 zsh 配置文件中,以克隆给定的 repo 以及 repo 中的所有分支。到目前为止我有
cloneAllBranches () {
repoName=$1
git clone repoName
dirName=$(echo "$repoName" | sed -E 's/^https:\/\/www\.github\.com\/([-_a-zA-Z0-9]+)\/([-_a-zA-Z0-9]+)\.git$/\2/')
cd dirName
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin/} $branch
done
}
目前我的 dirName Regex 返回完整的克隆路径,而不仅仅是目录名称。zsh regex 的新手,所以我不太确定我做错了什么。另外,我在Mac上。
zsh
可以自己做正则表达式匹配;没有必要使用sed
:
cloneAllBranches () {
repoName=$1
git clone "$repoName"
regex='^https?://www\.github\.com/([-_[:alnum:]])+/([-_[:alnum:]]+)\.git$'
[[ $repoName =~ $regex ]] || return
dirName=$match[2] # arrays are 1-indexed in zsh
...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句