-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.ps1
51 lines (42 loc) · 1.61 KB
/
github.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
param([switch]$VerboseSwitch = $false)
#$Verbose=$true -or $VerboseSwitch
$Verbose=$VerboseSwitch
# Write-Verbose "[$script] [$env:SnippetsInitialized] -not `$env:SnippetsInitialized: $(-not $env:SnippetsInitialized)" -Verbose:$Verbose
$script = $MyInvocation.MyCommand
if (-not $env:SnippetsInitialized) {
$fileInfo = New-Object System.IO.FileInfo (Get-Item $PSScriptRoot).FullName
$path = $fileInfo.Directory.FullName;
. $path/Snippets/_common.ps1;
Initialize-Snippets -Verbose:$Verbose
}
try {
if (-not $env:GITHUB) {
if($env:IsWindows -ieq 'true') {
$hintPath = "C:\"
} else {
$hintPath = "~"
}
Write-Verbose "[$script] searching for 'github' in [$hintPath]" -Verbose:$Verbose
$env:GITHUB = (Get-ChildItem -Filter github -Path $hintPath -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1).FullName
}
$description="Snippets: [dev] Go to GitHub folder [$env:GITHUB]"
Write-Verbose "[$script] `$env:GITHUB set to [$env:GITHUB]" -Verbose:$Verbose
function Set-LocationGitHub {
param(
[string]$Repository = '',
[switch]$V = $false
)
Write-Verbose "[$script] `$env:GITHUB: [$($env:GITHUB)]" -Verbose:$V
Write-Verbose "[$script] `$Repository: [$Repository]" -Verbose:$V
Set-Location (Join-Path $env:GITHUB -Child $Repository) -Verbose:$V
}
$alias = set-alias -Verbose:$Verbose -Scope Global -Description $description -Name hub -Value Set-LocationGitHub
return "Use ``hub`` to go to the GitHub folder."
}
catch {
Write-Host $Error
}
finally {
Write-Verbose '[github.ps1] Leaving...' -Verbose:$Verbose
$Verbose = $VerboseSwitch
}