1
- # 1.0.8007.19673
1
+ # 1.0.8030.25528
2
2
3
3
[CmdletBinding ()]
4
4
param ( [switch ]$completions )
5
5
6
- " C:\Portable Apps\Terraform" , `
7
6
" C:\Portable Apps\Helm" `
8
- | Add-DirectoryToPath
7
+ | Add-DirectoryToPath
9
8
10
9
if ($completions.IsPresent ) {
11
10
12
11
Write-Host " Loading CLI completions for docker | helm | kubectl." - ForegroundColor Cyan
13
12
14
- # # CLI completions require Git bash
15
-
16
- $__GIT_HOME = Join-Path - Path (Split-Path (Split-Path - Path (Get-Command " git" ).Source)) - ChildPath " bin"
17
- $__GIT_HOME | Add-DirectoryToPath - Prepend
18
-
19
13
Function Has-Module {
20
14
param ([string ]$name )
21
15
return [bool ] (Get-Module - ListAvailable - Name $name )
22
16
}
23
17
18
+ # # This function is taken from
19
+ # # https://github.com/springcomp/powershell_profile.ps1/blob/bb06eca65fda4d62c12269c8f770c562f8533c6c/Pwsh-Profile/Load-Profile.psm1#L14-L25
20
+ # #
21
+ # # TODO: allow module to run scripts in global scope instead of copying this function
22
+ Function Get-PwshExpression {
23
+ param ([string ]$path )
24
+
25
+ # # Using [IO.File]::ReadAllText() instead of Get-Content -Raw for performance purposes
26
+
27
+ $content = [IO.File ]::ReadAllText($path )
28
+ $content = $content -replace " (?<!\-)[Ff]unction\ +([_A-Za-z]+)" , ' Function global:$1'
29
+ $content = $content -replace " (?<!\-)[Ff]ilter\ +([_A-Za-z]+)" , ' Filter global:$1'
30
+ $content = $content -replace " [Ss][Ee][Tt]\-[Aa][Ll][Ii][Aa][Ss]\ +(.*)" , ' Set-Alias -Scope Global $1'
31
+
32
+ Write-Output $content
33
+ }
34
+ Function Install-DockerCompletion {
35
+ Install-Module DockerCompletion - Scope CurrentUser - Force
36
+ }
24
37
Function Install-KubeCompletion {
25
38
[CmdletBinding ()]
26
39
param ([Alias (" CompletionsPath" )][string ]$path )
27
- Install-Module DockerCompletion - Scope CurrentUser - Force
28
- Install-Module - Name PSBashCompletions - Scope CurrentUser - Force
40
+
41
+ # # kubectl completion for PowerShell required v1.23.x
42
+ $version = ConvertFrom-JSON - InputObject (kubectl version).Replace(" Client Version: version.Info" , " " )
43
+ if ($version.Minor -lt 23 ) {
44
+ Write-Host " kubectl CLI completion requires v1.23.0 or later. Please, upgrade kubectl.exe." - ForegroundColor Red
45
+ Write-Host " Please, refer to the following instructions to install kubectl:" - ForegroundColor Yellow
46
+ Write-Host " https://kubernetes.io/docs/tasks/tools/install-kubectl-windows" - ForegroundColor DarkGray
47
+ return
48
+ }
49
+
29
50
New-Item - Path $path - ItemType Directory - EA SilentlyContinue | Out-Null
30
- ((kubectl completion bash) -join " `n " ) | Set-Content - Encoding ASCII - NoNewline - Path $path / kubectl.sh
31
- ((helm completion bash) -join " `n " ) | Set-Content - Encoding ASCII - NoNewline - Path $path / helm.sh
51
+ kubectl completion powershell | Out-String | Set-Content - Encoding ASCII - NoNewline - Path $path / kubectl.ps1
52
+ }
53
+ Function Install-HelmCompletion {
54
+ [CmdletBinding ()]
55
+ param ([Alias (" CompletionsPath" )][string ]$path )
56
+ New-Item - Path $path - ItemType Directory - EA SilentlyContinue | Out-Null
57
+ helm completion powershell | Out-String | Set-Content - Encoding ASCII - NoNewline - Path $path / helm.ps1
32
58
}
33
59
34
60
$completionsPath = Join-Path (Split-Path - Parent $PROFILE ) Completions
35
- if ( ( -not (Has- Module DockerCompletion)) `
36
- -or (-not (Has - Module PSBashCompletions )) `
37
- -or ( -not ( Test-Path $completionsPath / kubectl.sh)) `
38
- -or ( -not ( Test-Path $completionsPath / helm.sh))
39
- ) {
61
+ if (-not (Has- Module DockerCompletion)) { Install-DockerCompletion }
62
+ if (-not (Test-Path $completionsPath / helm.ps1 )) {
63
+ Install-HelmCompletion - Completions $completionsPath
64
+ }
65
+ if ( -not ( Test-Path $completionsPath / kubectl.ps1) ) {
40
66
Install-KubeCompletion - Completions $completionsPath
41
67
}
42
68
43
69
Import-Module DockerCompletion
44
70
45
- if (Test-Path $completionsPath ) {
46
- Import-Module PSBashCompletions
47
- Register-BashArgumentCompleter kubectl " $completionsPath /kubectl.sh "
48
- Register-BashArgumentCompleter kc " $completionsPath /kubectl.sh "
49
- Register-BashArgumentCompleter helm " $completionsPath /helm.sh "
71
+ if (Test-Path $completionsPath / helm.ps1 ) {
72
+ Get-PwshExpression - Path " $completionsPath /helm.ps1 " | Invoke-Expression
73
+ }
74
+ if ( Test-Path $completionsPath / kubectl.ps1) {
75
+ Get-PwshExpression - Path " $completionsPath /kubectl.ps1 " | Invoke-Expression
50
76
}
51
77
}
52
78
53
79
Function compose { docker compose $args }
54
80
55
- Function tf-init {
56
- terraform init `
57
- - backend- config $PWD \tfbackend.tfvars
58
- $args
59
- }
60
- Function tf-plan {
61
- $varFile = Get-ChildItem - Path $PWD - Filter * .tfvars | ? { $_.Name -ne " tfbackend.tfvars" }
62
- terraform plan `
63
- - var- file " $PWD \$ ( $varfile.Name ) " `
64
- - var validate_datadog= false `
65
- $args
66
- }
67
- Function tf-apply {
68
- $varFile = Get-ChildItem - Path $PWD - Filter * .tfvars | ? { $_.Name -ne " tfbackend.tfvars" }
69
- terraform apply `
70
- - var- file " $PWD \$ ( $varfile.Name ) " `
71
- - var validate_datadog= false `
72
- - auto- approve `
73
- $args
74
- }
75
-
76
- Function tf-import {
77
- $varFile = Get-ChildItem - Path $PWD - Filter * .tfvars | ? { $_.Name -ne " tfbackend.tfvars" }
78
- terraform import `
79
- - var- file " $PWD \$ ( $varfile.Name ) " `
80
- - var validate_datadog= false `
81
- $args
82
- }
81
+ Set-Alias - Name " kube" - Value kubectl
82
+ Set-Alias - Name " kc" - Value kubectl
0 commit comments