If you provide the local name of the repo, it's really easy using $_:
git clone [email protected]:npm/npm.git npm-local-dir && cd $_
But if you don't want to re-type long names, it's a little ugly but doable with sed:
git clone [email protected]:pckujawa/pattern-rec.git &&
cd `echo $_ | sed -n -e 's/^.*\/\([^.]*\)\(.git\)*/\1/p'`
EDIT: Well, I was going to thank Manav (comment below) for the terse
git clone foo/bar && cd !$:t
but it doesn't work in zsh (something about how zsh does expansions causes it not to treat the first command as input to !$
). I had to look up what !$:t
did (Advancing in the Bash Shell | ${me:-whatever}). !$
grabs the last part of the previous command and :t
will "Remove all leading file name components, leaving the tail." Good information, but I wish I could get it to work with zsh (I tried noglob
with no success).
EDIT: Instead of using sed
or !$:t
(which doesn't work in zsh, for me anyway), I found two other options (one adapting https://unix.stackexchange.com/users/5685/frederik-deweerdt 's answer with https://unix.stackexchange.com/users/129926/henrik-n 's comment):
git clone [email protected]:npm/npm.git && cd $(basename $_ .git)
or
git clone [email protected]:npm/npm.git && cd ${${_%%.git*}##*/}
~/.bashrc
file (for example) and for me at least it didn't work, I needed to fix it with the replacing the line :/usr/bin/git "$@" 2>&1 | tee $tmp
cd
command aftergit clone
becomes a real burden?