Skip to content

Instantly share code, notes, and snippets.

@ThePyProgrammer
Created May 23, 2022 15:37
Show Gist options
  • Save ThePyProgrammer/a77945366edee96f67923f351090cc29 to your computer and use it in GitHub Desktop.
Save ThePyProgrammer/a77945366edee96f67923f351090cc29 to your computer and use it in GitHub Desktop.
A simple shell script to simplify the cloning process.
if (( $# == 1 )); then
# if only one argument is given (that is that directory = name of repo)
git clone $1
repo=$1
repo2arr=(${repo//// }) # split string into list by `/`
gitname=${repo2arr[-1]} # get last value
git2arr=(${gitname//./ }) # split by `.`
name=${git2arr[0]} # get first place
echo "Created repo at $name"
cd $name # move into directory
fi
if (( $# == 2 )); then
# if two arguments are used
git clone $1 $2
cd $2
fi
@ThePyProgrammer
Copy link
Author

I guess the best way to code this is as follows:

In your ~/.bashrc:

function clone() {
    if (( $# == 1 )); then
        git clone $1
        repo=$1
        repo2arr=(${repo//// })
        gitname=${repo2arr[-1]}
        git2arr=(${gitname//./ })
        name=${git2arr[0]}
        echo "Created repo at $name"
        cd $name
    fi
    if (( $# == 2 )); then
        git clone $1 $2
        cd $2
    fi
}

export -f clone

Then in Git Bash:

$ clone git_url.git <name of directory (optional)>

Copy link

ghost commented Nov 17, 2022

Hi, how are you I hope you doing well? I did grab some of the scripts but I find 12 errors during the paste back to my VS code.
But yes I love to automatize processes.

@ThePyProgrammer
Copy link
Author

May I clarify as to which OS you are currently operating on? This is, of course, a very Bash-focused thing. I use Windows, so I have been adapting it to Git Bash, but it's possible that it's not exactly applicable for other OS .bashrcs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment