This is lazy programmer request. I would like to create a shell script automate the following process:
git clone <remote-repo-url>
cd <cloned-folder>
open <cloned-folder>
So the idea here is to clone a URL and then immediately cd
into the cloned-folder
. The trick here is to identify the cloned-folder
from the url pattern.
For now we can assume that url structure is in this pattern .../<cloned-folder>.git
i.e. the url.
I am wondering if we can actually do with using awk
or some tools like that. The part i am stuck is finding a appropriate regex
, I guess.
USE CASE: Here the use case is if you clone a url, you want to be in the repofolder as soon as possible. The is the pre-requirement if you want to run any git
command like git log
or mate .
which we do 99% of the time.
Thanks in advance.
Instead of getting directory name from url, we could just
cd
into the latest created directory. Here is the corresponding shell script:bash function to do this (works in zsh also):
The
awk
command prints the part after the last/
(e.g fromhttp://example.com/myrepo.git
tomyrepo.git
). Thesed
command removes the trailing.git
Usage:
With git clone, you can specify the folder to clone to, instead of allowing it to be named automatically.
The bash parameter version is quite nice, I went with
basename
cuz it seemed cleanerI use short memorable tab-completable function names for a bunch of things like this and put them in my
.bashrc
as aliases/functions, e.g.gcmmt
forgit commit -m
.lazy
may well already be a prefix for things in your shell, which means it's that little bit more to type each time...An improvement from @dbr's answer:
With the help of Bash's parameter expansion, we can get rid of
awk
andsed
.