John Lindquist: 0:00 We want to clone this URL from Chrome from our terminal. The way we get that URL is by using osascript, which can run AppleScript. We need to pass in the -e flag, or else it's going to look for a script on the computer. The statement looks like this, "Tell application Google Chrome to return URL of active tab of front window."
0:24 When I run that, you'll see that we get our URL back. Let's store that in a variable. We're going to wrap this in parentheses so that it executes inside of there, and set URL equal to that, hit enter. Now if we echo our URL, you'll see we have the URL stored. We're going to want this chunk of text here so that we have the username and the project so that we can append it to get clone statement.
0:48 We'll break apart that string using this syntax, URL at 19. I'll go ahead and echo that. I counted ahead of time that this is 19 characters. We're just removing that from the rest of this.
1:01 We'll go ahead and assign repo to that. We'll check if we have our repo, which we do. Then, lastly, once it clones it to my folder, the name of the project is going to be promises-in-rxjs. I'm going to need this bit of text. I'm going to clear this out.
1:17 Finally, from the repo, we can tell it to extract the tail. This syntax is called parameter expansion. It's going to find that last slash and take everything after it. We'll go ahead and echo that. You can see we have the project name.
1:31 To put this all together, we will create a function named clone. We'll go into our projects directory. I'll copy and paste our URL command. Remember, that's the full URL. Then our repo will be the characters after the 19th character, so this is getting rid of github.com and https. Then the name of our project is the tail of the repo name, so tail of the repo name.
1:55 Then we can go ahead and git clone email@example.com and then tack on the repo name. Once that's done, we can tell our IDE -- I'm using Visual Studio Code -- to open the name, since we'll be in our current project and this project will have cloned there. Code can just go ahead and open that.
2:14 Once I go back to my terminal here, let's clear this out. I'll even go up a directory. I'll make sure that this is the frontmost window here and make sure to source my zshrc. Then, once I type clone, you'll see the whole process run through. It'll pop open code with everything cloned and ready to work on.