gg
gg copied to clipboard
`gg cl` to move inside cloned directory
When most people use the git clone
command, they just directly move inside the directory with cd
.
I'm suggesting to make gg cl
automatically change the current directory to the cloned repo... or maybe add a new command?
Thanks!
This is a great idea! Sadly, AFAIK, there is no way to do this without introducing an external script that changes the directory which you would then source
in the main script.
If there is an elegant solution, I would love to have this implemented!
Taken from http://unix.stackexchange.com/questions/97920/how-to-cd-automatically-after-git-clone
It may be a starting point.
git()
{
local tmp=$(mktemp)
local repo_name
if [ "$1" = clone ] ; then
/usr/bin/git "$@" | tee $tmp
repo_name=$(awk -F\' '/Cloning into/ {print $2}' $tmp)
rm $tmp
printf "changing to directory %s\n" "$repo_name"
cd "$repo_name"
else
/usr/bin/git "$@"
fi
}
This is essentially creating the directory beforehand and them cloning into that directory, which is a valid solution except the issue we are running into is related to how Shell scripts execute commands.
In a Shell script, a subshell is created. cd
will change the directory of the subshell, which is different from the shell that is executing the script (i.e. the user's terminal).