kubectl provides autocompletion support for various operating systems such as Bash, Zsh, Fish, and Windows PowerShell. This can save a lot of typing and trying to remember the exact command format.
Setup kubectl Autocomplete in Windows
To enable kubectl autocomplete in Windows Powershell, run the following command in your Powershell terminal Window:
kubectl completion powershell | Out-String | Invoke-Expression
To save having to type this command every time you invoke a new terminal, you can add the command to your Powershell $PROFILE
file.
To find the location of your $PROFILE
file, type the following command:
echo $PROFILE
To edit your profile file directly from within Powershell, enter:
notepad $PROFILE
If the profile file is not present, you will be asked if you would like to create one. Add the command into the profile file and save. Close and re-open your Powershell terminal and autocomplete should be working.
Hey Kerry when I execute the command ‘notepad $PROFILE’ it shows system cannot find the path specified
Hi Kiran! Your Windows Powershell profile is usually located here:
C:\Users\your-username\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
If you do not have the profile (or folder) already created then you can create them as follows from within your Windows Powershell window:
cd C:\Users\your-username\Documents
mkdir WindowsPowerShell
cd WindowsPowerShell
echo dummytext > Microsoft.PowerShell_profile.ps1
notepad Microsoft.PowerShell_profile.ps1
Enter the commands you need into the profile file, save it, open a new WIndows Powershell window and you should be good to go!