Created
March 16, 2021 03:56
-
-
Save instance-id/6251adc9ebe2d13116410078ec5270ee to your computer and use it in GitHub Desktop.
A Linux PowerShell script to clone a GitHub repo and then go to that directory. Because I wanted to, that's why.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env pwsh | |
# -- Either make sure clone.ps1 is on your path, | |
# -- or use the full path in the alias | |
# -- You can then setup the following Alias | |
# -- alias clone='f() { cd $(clone.ps1 $1) };f' | |
# -- Usage: ~ » clone github.com/instance-id/desiredrepo | |
Param ( | |
[Parameter(ValueFromPipeline = $true)][string]$gitUrl | |
) | |
# -- Set this to your github folder | |
$githubPath = '/mnt/x/GitHub' | |
if ($([System.IO.Path]::GetExtension($gitUrl)) -notmatch '.git') { | |
$gitUrl += '.git' | |
} | |
$qualifier = $($gitUrl | Split-Path -Qualifier -ErrorAction Ignore) | |
if ($null -eq $qualifier) { | |
$gitUrl = "git://${gitUrl}" | |
} | |
$pathName = $([System.IO.Path]::GetFileNameWithoutExtension($gitUrl)) | |
$clonePath = "${githubPath}/$pathName" | |
& git clone $gitUrl $clonePath | |
return ${clonePath} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment