簡體   English   中英

kubectl 別名和自動完成不適用於 powershell

[英]kubectl alias and autocomplete not working for powershell

嘗試在 Windows Server 2022 上使用Windows PowerShellPowerShell Core使kubectl自動完成功能與別名k一起使用,但無法使其正常工作

測試了

echo 'Set-Alias -Name k -Value kubectl' >> $PROFILE
kubectl completion powershell >> $PROFILE

或者甚至只是嘗試讓它在同一個 session 中工作,而不用擔心將其保存到 PowerShell 配置文件

Set-Alias -Name k -Value kubectl
kubectl completion powershell | Out-String | Invoke-Expression

到目前為止的結果:

Powershell 5.1
使用kubectl完成制表符: OK
使用k完成制表符:失敗

Powershell 核心 7.3
使用kubectl完成制表符:失敗
使用k完成制表符:失敗

上面的結果是用Windows Terminalcmd測試的

我錯過了一些明顯的東西嗎? (就像我平時做的那樣)

謝謝!

所以 go 它在 PowerShell 5.1 上工作,並假設 Cobra 只在 Powershell 5.x 上工作,所以放棄讓 PowerShell 核心工作!

# Powershell 5.x
echo 'Set-Alias -Name k -Value kubectl' >> $PROFILE
echo 'Register-ArgumentCompleter -CommandName k -ScriptBlock $__kubectlCompleterBlock'  >> $PROFILE
kubectl completion powershell >> $PROFILE
# Reload the PowerShell profile
. $PROFILE

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM