gg icon indicating copy to clipboard operation
gg copied to clipboard

`gg cl` to move inside cloned directory

Open mkody opened this issue 8 years ago • 3 comments

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!

mkody avatar Aug 19 '15 09:08 mkody

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!

qw3rtman avatar Oct 13 '15 03:10 qw3rtman

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
}

professorjamesmoriarty avatar Oct 13 '15 03:10 professorjamesmoriarty

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).

Here's a better explanation.

qw3rtman avatar Oct 13 '15 03:10 qw3rtman