Window & Powershell Initializing Setup

Oct 16, 2022 · windows, powershell, neovim

Seting up a new working environment for Windows. Since my company assign me a window11 workstation in my onboarding day, I realize that I need to have to workaround with Windows an PowerShell. Hope there’s something you guys can use 😃.

Terminal

1. PowerShell 7

Windows came with PowerShell 5.1 by default. If you’re willing to try, here’s the tutorial.

2. Windows Terminal

PowerShell

1. Chocolately

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

2. Shell promt with oh-my-posh

After a while, I found oh-my-posh 😕. Yep, that’s it. Similar to what I normally use for Zsh in Linux, and also has the built-in spaceship-promt

Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))
notepad $PROFILE

⚠ Create new Profile if doesn’t exist:

New-Item -Path $PROFILE -Type File -Force
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/${YOUR_THEME}.omp.json" | Invoke-Expression

You can choose whatever you want in the built-in theme list and replace the ${YOUR_THEME} with it.

3. Shell auto-completions & auto-suggestions

Do you get tired of typing CTRL+R to look up commands in the history? Similar to zsh-autosuggestions, simply add the following to your profile:

# up&down arrow for history search 
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward 
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

Add one more if you’d like to view all autocomplete options after pressing TAB:

# menu complete using TAB instead of CTRL+SPACE
Set-PSReadlineKeyHandler -Chord Tab -Function MenuComplete

4. MagicTooltips

This gif explain everything 😆. demo

Install-Module MagicTooltips
$global:MagicTooltipsSettings = @{
    HorizontalAlignment = "Right"
    VerticalOffset = 0
    HorizontalOffset = 2
    Providers= @{
        Azure = @{
            Commands = "az,terraform,pulumi,terragrunt"
            FgColor = "#3A96DD"
            Template = "\ufd03 {value}"
        }
        Kubernetes = @{
            Commands = "k,kubectl,helm,kubens,kubectx,oc,istioctl,kogito,k9s,helmfile"
            FgColor = "#3970e4"
            Template = "\ufd31 {value}"
        }
        Aws = @{
            Commands = "aws,awless,terraform,pulumi,terragrunt"
            FgColor = "#EC7211"
            BgColor = ""
            Template = "\uf270 {value}"
        }
    }
}
Import-Module MagicTooltips

Neovim

For me, who start with the Linux Vim since the first day, Window Notepad or even Notepad++ such a pain for typing 😅.

choco install neovim
iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |`
    ni "$(@($env:XDG_DATA_HOME, $env:LOCALAPPDATA)[$null -eq $env:XDG_DATA_HOME])/nvim-data/site/autoload/plug.vim" -Force

vim-init.png

Docker & Docker-compose

Kubectl

Helm