Clone-Git.ps1
function Clone-Git{ [CmdletBinding(DefaultParameterSetName='ClipBoard')] [Alias('cgit')] param( [Parameter(ParameterSetName='Repo',Mandatory,Position = 0,ValueFromPipeline)] [String[]]$Repo, [Parameter(ParameterSetName='ClipBoard',Position = 0)] [switch]$ClipBoard, [Parameter(Mandatory,Position = 1)] [ValidateScript({ if(-Not ([IO.Directory]::Exists($(Resolve-Path -Path $_))) ) { throw [IO.DirectoryNotFoundException]::new("Unable to locate - $_") } return $true })] [IO.DirectoryInfo]$Path ) Begin { if ([Environment]::GetEnvironmentVariable('GIT_REDIRECT_STDERR') -ne '2>&1') { throw 'Confirm Env Variable - GIT_REDIRECT_STDERR = 2>&1' } Write-Verbose -Message ("Setting `$Dir to {0}" -f $PWD.Path) $Dir = $PWD.Path $Loc = Resolve-Path -Path $Path Write-Verbose -Message ('Set-Location: {0}' -f $Loc) Set-Location -Path $Loc } Process { Write-Verbose -Message ('Parameter Set Name: {0}' -f $PSCmdlet.ParameterSetName) $RepoLoc = switch ($PSCmdlet.ParameterSetName) { 'ClipBoard' { Get-Clipboard -Format Text ; break } 'Repo' { $Repo ; break } default { throw "Error setting `$RepoLoc" } } foreach ($RepoUrl in $RepoLoc) { Write-Verbose -Message ('Cloning: {0}{1}{2}' -f $RepoUrl,"`n",$(Join-Path -Path $Loc -ChildPath $(Split-Path -Path $RepoUrl -Leaf).Split('.')[0])) -Verbose git clone --recursive $RepoUrl } } End { Write-Verbose -Message ('Returning to : {0}' -f $Dir) Set-Location -Path $Dir } } |