Sau*_*abh 6 git shell automation
这是懒惰的程序员请求.我想创建一个shell脚本自动执行以下过程:
git clone <remote-repo-url>
cd <cloned-folder>
open <cloned-folder>
Run Code Online (Sandbox Code Playgroud)
所以这里的想法是克隆一个URL,然后立即cd
进入cloned-folder
.这里的技巧是cloned-folder
从url模式中识别.
现在我们可以假设url结构是这种模式,.../<cloned-folder>.git
即url.
我想知道我们是否可以实际使用awk
或使用这样的工具.regex
我想,我遇到的部分是找到合适的.
使用例:这里使用的情况是,如果你克隆一个网址,要尽快将在repofolder.如果您想要运行任何git
命令,git log
或者mate .
我们在99%的时间内执行,那么这是预先要求.
提前致谢.
dbr*_*dbr 14
bash函数执行此操作(也适用于zsh):
function lazyclone {
url=$1;
reponame=$(echo $url | awk -F/ '{print $NF}' | sed -e 's/.git$//');
git clone $url $reponame;
cd $reponame;
}
Run Code Online (Sandbox Code Playgroud)
该awk
命令打印最后一个部分/
(例如从http://example.com/myrepo.git
到myrepo.git
).该sed
命令删除尾随.git
用法:
$ pwd
~/
$ lazyclone https://github.com/dbr/tvdb_api.git
tvdb_api
Cloning into 'tvdb_api'...
remote: Counting objects: 1477, done.
remote: Compressing objects: 100% (534/534), done.
remote: Total 1477 (delta 952), reused 1462 (delta 940)
Receiving objects: 100% (1477/1477), 268.48 KiB | 202 KiB/s, done.
Resolving deltas: 100% (952/952), done.
$ pwd
~/tvdb_api
Run Code Online (Sandbox Code Playgroud)