Friday, April 26, 2024
HomePowershellHow I Setup My Powershell Growth Surroundings

How I Setup My Powershell Growth Surroundings


On this publish i’ll stroll by means of the method of how i setup my PowerShell growth environement on a Home windows PC. This information has been made on a Home windows 11 PC, so in case you are operating Home windows 10, you may expertise that a number of the utility or instruments, should be put in a unique means.

On this tutorial i’ll present how one can setup the 2 package deal managers Scoop and Chocolatey, I’ll present you to make use of the package deal managers to put in instruments like: vscode, git and neovim. I will even present how one can setup WSL2, Docker Desktop and neovim for enhancing PowerShell scripts within the Terminal.

Stipulations

  1. Home windows 11 PC
  2. Connection to the web

Putting in the Chocolatey and Scoop package deal Managers

I attempt to set up as many instruments and purposes as attainable by means of one of many two package deal managers. The explanation for this, is that with the package deal supervisor you could have quick access for updating your purposes, and this can be very straightforward in comparison with exit to completely different web sites, discovering the right model, downloading and putting in by means of a GUI.

Putting in Chocolatey

For putting in chocolatey it’s as straightforward as operating a easy PowerShell command.

  1. Open a PowerShell terminal as Administrator

  2. Run the next command:

1
Set-ExecutionPolicy Bypass -Scope Course of -Drive; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Web.WebClient).DownloadString('https://group.chocolatey.org/set up.ps1'))
  1. You now have Chocolatey put in. To confirm this you may run the next command:

output:

Essential factor to know is that everytime you need to set up a package deal with chocolatey you have to to open the PowerShell terminal as Administrator.

Putting in Scoop

For putting in Scoop it’s simply so simple as putting in Chocolatey, and will be carried out with a single command

  1. Open a PowerShell terminal as Administrator

  2. Run the next command:

1
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser; Invoke-WebRequest get.scoop.sh | Invoke-Expression
  1. You now have Scoop put in. To confirm this you may run the next command:

output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Utilization: scoop <command> [<args>]

Some helpful instructions are:

alias       Handle scoop aliases
bucket      Handle Scoop buckets
cache       Present or clear the obtain cache
cat         Present content material of specified manifest. If out there, `bat` shall be used to pretty-print the JSON.
checkup     Verify for potential issues
cleanup     Cleanup apps by eradicating outdated variations
config      Get or set configuration values
create      Create a customized app manifest
relies upon     Record dependencies for an app
    ...

Essential to know is that in case you are putting in packages with scoop, you could typically want to make use of a PowerShell terminal in Administrator context, and typically in Consumer context. I often begin by making an attempt with a non-administrator PowerShell terminal.

Now you may want so as to add Scoop to your Surroundings Variable Path, earlier than you may actualy use the package deal supervisor.

/images/how-i-setup-my-powershell-development-environment/image1.png

Updating the Home windows Terminal

Relying on which construct you might be on, you may have to replace your Home windows Terminal utility to a more recent model, to get some newer options. In my case i wanted to replace the appliance.

Now you may both fully uninstall the appliance after which set up it by means of Chocolatey by operating the command:

1
choco set up microsoft-windows-terminal

You too can simply replace the appliance by means of the Microsoft Retailer. You do that by opening the Retailer, seek for “Home windows Terminal” and click on on “Replace”.

Putting in Home windows Subsystem for Linux

I exploit Home windows Subsystem for Linux quiet a bit, for growing PowerShell 7 scripts for Linux or completely different purposes resembling Python.

To put in WSL2 open a PowerShell terminal as administrator and enter the command:

The putting in will take a few minutes and as soon as carried out, you have to to restart the pc.

Now as default WSL2 will set up Ubuntu on you system. So as soon as your laptop has restarted you can be prompted to finish the setup of you Ubuntu occasion.

To finish the ubuntu setup you have to to pick out a Username and Password for the person.

I all the time run a whole replace of the Ubuntu occasion with the command:

1
sudo apt replace && sudp apt improve -y

Putting in Packages

I all the time set up the next packages:

Package deal Description Package deal Supervisor
VSCode IDE for writing code Chocolatey
git Supply Management utility Chocolatey
Docker Desktop Container runtime, and administration utility Chocolatey
Picpick Screenshot instrument Chocolatey
Neovim Terminal textual content editor Scoop
Fuzzy Terminal Search instrument Scoop
Curl Terminal http instrument Scoop
Sudo Terminal instrument for administrator elevation Scoop
Jq Terminal json parsing instrument Scoop

Putting in the Chocolatey Packages:

1
choco set up vscode git docker-desktop picpick.moveable

Putting in the Scoop Packages:

1
scoop set up neovim fzf curl sudo jq

Putting in PowerShell 7

You possibly can set up PowerShell 7 in two alternative ways. You possibly can both set up it by means of the MSI supplied by Microsoft on their web site, or you may set up it by means of Chocolatey

Putting in by means of Chocolatey:

1
choco set up powershell-core

Putting in by means of Microsoft supplied MSI:

Hyperlink to Microsoft Docs – Putting in PowerShell 7

Each methods present PowerShell 7 model 7.2.3 on the time of penning this publish. However should you needed to run with PowerShell preview you can set up it by means of Chocolatey by operating the command:

1
choco set up powershell-preview

Now i might often check out a preview model in a Docker container, after which operating a secure model on my system.

Putting in a Nerd Font

To have the ability to use oh-my-posh and Terminal-Icons within the terminal, which I’ll present within the subsequent step, you have to to put in a Nerd Font and set it up in Home windows Terminal. The explanation for that is {that a} Nerd Font is ready to show icons within the terminal, which an everyday font just isn’t.

First you have to to obtain a Font, and also you do that by going to Nerd Fonts downloads web page after which deciding on a font you want. I often go together with Hack Nerd Font.

/images/how-i-setup-my-powershell-development-environment/download-nerd-font.png

As soon as the fonts are downloaded, you have to to extract the content material. Then within the extracted folde, choose all of the recordsdata. Proper click on after which choose ‘Set up’. This may set up the font to your system.

All you’ll want to do now’s to pick out the font as default in your Home windows terminal. You do that by opening Settings, and below “Profiles” choose “Defaults”. Then below “Extra settings” choose “Look”, and below “Font face” now you can choose the font you downloaded.

/images/how-i-setup-my-powershell-development-environment/windows-terminal-fonts.png

Organising my PowerShell Terminal

I’ve my PowerShell terminal setup with some particular instruments which helps me when working in git repositories, and with some instruments for straightforward navigation within the terminal.

First i might want to set up a instrument named oh-my-posh. This instrument is used for displaying completely different data in terminal, resembling which listing you might be in, and standing of your git repository.

To put in oh-my-posh run the command:

1
scoop set up https://github.com/JanDeDobbeleer/oh-my-posh/releases/newest/obtain/oh-my-posh.json

Then I’ll set up the next PowerShell modules:

  • ‘Terminal-Icons’ – (used for displaying icons within the terminal resembling directories and recordsdata)
  • ‘Z’ – (This module is a listing navigation instrument)
  • ‘PSFzf’ – (Listing Navigation and file looking instrument for the terminal)
  • ‘PSReadLine’ – (Instrument for offering autosuggestion and completion within the terminal primarily based on historical past)

Set up the modules by operating the instructions:

1
2
3
4
5
6
7
Set up-Module Terminal-Icons -Scope CurrentUser

Set up-Module Z -Scope CurrentUser

Set up-Module PSFzf -Scope CurrentUser

Set up-Module PSReadLine -AllowPrerelease -Scope CurrentUser -Drive -SkipPublisherCheck

The very last thing i’ll do is to configure my PowerShell profile. I solely run some easy factor within the profile, resembling importing modules, initializing oh-my-post and setting som aliases.

to create a PowerShell profile run the command:

Then add the next to the .ps1 script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Configuring Oh-my-posh Terminal
oh-my-posh init pwsh --config "$(scoop prefix oh-my-posh)themesamro.omp.json" | Invoke-Expression

# Importing Terminal-Icons Module
Import-Module Terminal-Icons

# Importing Z Module
Import-Module Z

# Importing Fuzzy finder instrument
Import-Module PSFzf

# Configuring Fuzzy Finder
Set-PSReadLineOption -PredictionSource Historical past
Set-PsFzfOption -PSReadLineChordProvider 'Ctrl+f' -PSreadLineChordReverseHistory 'Ctrl+r'




# Setting Alias's
Set-Alias vim nvim
Set-Alias g git
Set-Alias grep Discover-String

Save the file, and in your powershell terminal you have to to re-initialize the PowerShell profile

Configuring VSCode

I’ve a really fundamental setup for my vscode. I solely set up a handfull of extensions after which i set some customized hotkeys, for switching between the editor and the terminal.

Putting in vscode extension

For putting in the extensions i’ve created a quite simple script which runs by means of an array of extensions and installs them. You possibly can edit the array as you want, after which simply run the script.

 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
$extensions = @(
    "aaron-bond.better-comments",
    "ecmel.vscode-html-css",
    "esbenp.prettier-vscode",
    "HansUXdev.bootstrap5-snippets",
    "ms-azuretools.vscode-azurefunctions",
    "ms-azuretools.vscode-azureresourcegroups",
    "ms-azuretools.vscode-bicep",
    "ms-azuretools.vscode-docker",
    "ms-dotnettools.vscode-dotnet-runtime",
    "ms-python.python",
    "ms-python.vscode-pylance",
    "ms-toolsai.jupyter",
    "ms-toolsai.jupyter-keymap",
    "ms-toolsai.jupyter-renderers",
    "ms-vscode-remote.remote-wsl",
    "ms-vscode.azure-account",
    "ms-vscode.powershell",
    "PKief.material-icon-theme",
    "pspester.pester-test",
    "rangav.vscode-thunder-client",
    "redhat.vscode-yaml",
    "richie5um2.vscode-sort-json",
    "ritwickdey.LiveServer",
    "yzhang.markdown-all-in-one",
    "zhuangtongfa.material-theme"
)

operate Set up-VSCodeExtensions {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$false, HelpMessage="Array containing all vscode extensions needed")]
        [Array]$Extensions = $extensions
    )

    foreach($extension in $Extensions) {
        attempt {
            code --install-extension $extension
            Write-Verbose -Message "Putting in vscode extension: $($extension)"
        }
        catch {
            Write-Error "Failed putting in extension: $($extension)"
        }
    }
}


Set up-VSCodeExtensions -Extensions $extensions -Verbose

Configuring vscode hotkeys

To configure the hotkeys, open vscode, pres ctrl+shift+p to open the command pallet. Then seek for ‘Shortcuts’ and open the ‘Preferences: Open Keyboard Shortcuts (JSON)’.

Then add the next traces between ‘[]’

1
2
{ "key": "alt+proper", "command": "workbench.motion.terminal.focus"},
{ "key": "alt+left", "command": "workbench.motion.focusActiveEditorGroup", "when": "terminalFocus"}

These hotkeys can help you change between the editor and the terminal with the hotkeys: ‘alt+proper’ and ‘alt+left’

Configuring Neovim

I exploit Neovim queit usually, since i’m utilizing the terminal for just about every little thing which need to do with navigation in Home windows, and sometimes i might want to edit a single line in a script of config file. As an alternative of getting to open a vscode editor it’s often simpler and faster to only open til file inside Neovim.

Neovim comes fairly commonplace which could not be the best approach to edit PowerShell scripts with.

First you have to to creat the init.vim config file. This file is the place all of the configs for the editor is positioned.

Create the next recordsdata:

1
2
3
New-Merchandise -Path '~/AppData/Native/nvim' -ItemType Listing
New-Merchandise -Path '~/AppData/Native/nvim/autoload' -ItemType Listing
New-Merchandise -Path '~/AppData/Native/nvim/init.vim' -ItemType File

Then run the next command to put in vimplug:

1
2
iwr -useb https://uncooked.githubusercontent.com/junegunn/vim-plug/grasp/plug.vim |`
    ni ~/AppData/Native/nvim-data/web site/autoload/plug.vim -Drive

Then open the file: init.vim in vscode and add the next settings:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
" Organising pluggable
name plug#start('~AppDataLocalnvimautoloadplugged')
Plug 'https://github.com/scrooloose/nerdtree'
Plug 'sheerun/vim-polyglot'
Plug 'neoclide/coc.nvim', {'department': 'launch'}
name plug#finish()

filetype plugin indent on
" present current tab with 4 areas width
set tabstop=4
" when indenting with '>', use 4 areas width
set shiftwidth=4
" On urgent tab, insert 4 areas
set expandtab

" Setting line numbering
set quantity


" Setting coc to automaticly set up coc-powershell
let g:coc_global_extensions=[ 'coc-powershell']

" At all times show NERDTree when opening nvim
autocmd VimEnter * NERDTree

Now you have to to put in the completely different plugins for PowerShell syntax highlighting and code completion. To do that open Neovim by coming into ‘vim’ within the terminal.

Then press ‘:’ and write PlugInstall

This may set up all of the wanted plugins.

The one factor left to do is to create a brand new file for disabling the built-in terminal in Neovim.

open a brand new vim editor and write

:CocConfig

Then add the next to the file:

1
2
3
{
    "powershell.integratedConsole.showOnStartup": false
}

It’s best to now have a working Neovim setup for enhancing and writing Powershell code

/images/how-i-setup-my-powershell-development-environment/nvim-powershell-setup.png

On this ending part i’ll simply shortly stroll over how one can use a number of the instruments or how one can look

The Oh-My-Posh module and the Terminal Icons Instrument

/images/how-i-setup-my-powershell-development-environment/image2.png

Utilizing the PSReadLine

The configs for the PSReadline is ready to make use of the PowerShell command historical past to autosuggest attainable instructions:

/images/how-i-setup-my-powershell-development-environment/image3.png

Utilizing the Module Z

The Module Z is a fast listing Navigation instrument.

Use the next command to see attainable directoris:

/images/how-i-setup-my-powershell-development-environment/image4.png

The go to a listing by including a phrase from one of many directories after a ‘z’:

/images/how-i-setup-my-powershell-development-environment/image5.png

Utilizing Fuzzy Finder

Use ‘Ctrl+r’ to navigate by means of your powershell historical past. In the event you kind one thing the listing will slender to the particular textual content.

/images/how-i-setup-my-powershell-development-environment/image6.png

Use ‘Ctrl+f’ to look by means of your present listing

/images/how-i-setup-my-powershell-development-environment/image7.png

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments