Navigate back to the homepage

Pretty Windows Terminal and PowerShell Setup

Dominic Böttger
April 13th, 2020 · 2 min read

The new Windows Terminal is a big step forward for all people who like to work with the command line. It’s available in the Store or via Chocolatey. I suggest using the Store version to automatically stay up to date.

I did some modifications to the basic Terminal and PowerShell configuration which can eventually be helpful for some people.

PowerShell modules used by my configuration:

  • posh-git: Provides status information about a repository and offers tab completion in the terminal.

  • oh-my-posh: Beautifies the terminal

  • z: It’s a port of the z bash shell script and lets you quickly navigate through your filesystem based on your history. For instance, if you once did a z ~/development/project and the next time just enter z project you will be guided to the same directory.

Installation

Choco - Package manager for windows:

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

PowerShell Core: I typically use the core version of PowerShell.

1choco install powershell-core

Cascadia Code Font: A font supporting Powerline and Ligatures

1choco install cascadiacodepl

Windows Terminal: I recommend installing the Terminal from the Microsoft Store. https://www.microsoft.com/store/productId/9N0DX20HK701

Configuration

First, you should configure your Terminal settings and especially set the font to “Cascadia Code PL”.

To open the configuration for the Windows Terminal open the Windows Terminal application and click on the “down-arrow” - sign next to the tab bar and click on “Settings”. This will open a text editor with the profiles.json.

Image shows how to open the Terminal settings

My Terminal configuration looks like that ( it defaults to PowerShell core )

1{
2 "$schema": "https://aka.ms/terminal-profiles-schema",
3 "globals" :
4 {
5 "alwaysShowTabs" : true,
6 "defaultProfile" : "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
7 "initialCols" : 120,
8 "initialRows" : 30,
9 "keybindings" :
10 [
11 {
12 "command" : "closeTab",
13 "keys" :
14 [
15 "ctrl+w"
16 ]
17 },
18 {
19 "command" : "newTab",
20 "keys" :
21 [
22 "ctrl+t"
23 ]
24 },
25 {
26 "command" : "newTabProfile0",
27 "keys" :
28 [
29 "ctrl+shift+1"
30 ]
31 },
32 {
33 "command" : "newTabProfile1",
34 "keys" :
35 [
36 "ctrl+shift+2"
37 ]
38 },
39 {
40 "command" : "newTabProfile2",
41 "keys" :
42 [
43 "ctrl+shift+3"
44 ]
45 },
46 {
47 "command" : "newTabProfile3",
48 "keys" :
49 [
50 "ctrl+shift+4"
51 ]
52 },
53 {
54 "command" : "newTabProfile4",
55 "keys" :
56 [
57 "ctrl+shift+5"
58 ]
59 },
60 {
61 "command" : "newTabProfile5",
62 "keys" :
63 [
64 "ctrl+shift+6"
65 ]
66 },
67 {
68 "command" : "newTabProfile6",
69 "keys" :
70 [
71 "ctrl+shift+7"
72 ]
73 },
74 {
75 "command" : "newTabProfile7",
76 "keys" :
77 [
78 "ctrl+shift+8"
79 ]
80 },
81 {
82 "command" : "newTabProfile8",
83 "keys" :
84 [
85 "ctrl+shift+9"
86 ]
87 },
88 {
89 "command" : "nextTab",
90 "keys" :
91 [
92 "ctrl+tab"
93 ]
94 },
95 {
96 "command" : "openSettings",
97 "keys" :
98 [
99 "ctrl+,"
100 ]
101 },
102 {
103 "command" : "prevTab",
104 "keys" :
105 [
106 "ctrl+shift+tab"
107 ]
108 },
109 {
110 "command" : "scrollDown",
111 "keys" :
112 [
113 "ctrl+shift+down"
114 ]
115 },
116 {
117 "command" : "scrollDownPage",
118 "keys" :
119 [
120 "ctrl+shift+pgdn"
121 ]
122 },
123 {
124 "command" : "scrollUp",
125 "keys" :
126 [
127 "ctrl+shift+up"
128 ]
129 },
130 {
131 "command" : "scrollUpPage",
132 "keys" :
133 [
134 "ctrl+shift+pgup"
135 ]
136 },
137 {
138 "command" : "switchToTab0",
139 "keys" :
140 [
141 "alt+1"
142 ]
143 },
144 {
145 "command" : "switchToTab1",
146 "keys" :
147 [
148 "alt+2"
149 ]
150 },
151 {
152 "command" : "switchToTab2",
153 "keys" :
154 [
155 "alt+3"
156 ]
157 },
158 {
159 "command" : "switchToTab3",
160 "keys" :
161 [
162 "alt+4"
163 ]
164 },
165 {
166 "command" : "switchToTab4",
167 "keys" :
168 [
169 "alt+5"
170 ]
171 },
172 {
173 "command" : "switchToTab5",
174 "keys" :
175 [
176 "alt+6"
177 ]
178 },
179 {
180 "command" : "switchToTab6",
181 "keys" :
182 [
183 "alt+7"
184 ]
185 },
186 {
187 "command" : "switchToTab7",
188 "keys" :
189 [
190 "alt+8"
191 ]
192 },
193 {
194 "command" : "switchToTab8",
195 "keys" :
196 [
197 "alt+9"
198 ]
199 }
200 ],
201 "requestedTheme" : "system",
202 "showTabsInTitlebar" : true,
203 "showTerminalTitleInTitlebar" : true
204 },
205 "profiles" :
206 [
207 {
208 "acrylicOpacity" : 0.5,
209 "background" : "#012456",
210 "closeOnExit" : true,
211 "colorScheme" : "Campbell",
212 "commandline" : "powershell.exe",
213 "cursorColor" : "#FFFFFF",
214 "cursorShape" : "bar",
215 "fontFace" : "Cascia Code PL",
216 "fontSize" : 10,
217 "guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
218 "historySize" : 9001,
219 "icon" : "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
220 "name" : "Windows PowerShell",
221 "padding" : "0, 0, 0, 0",
222 "snapOnInput" : true,
223 "startingDirectory" : "%USERPROFILE%",
224 "useAcrylic" : false
225 },
226 {
227 "acrylicOpacity" : 0.75,
228 "closeOnExit" : true,
229 "colorScheme" : "Campbell",
230 "commandline" : "cmd.exe",
231 "cursorColor" : "#FFFFFF",
232 "cursorShape" : "bar",
233 "fontFace" : "Cascia Code PL",
234 "fontSize" : 10,
235 "guid" : "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
236 "historySize" : 9001,
237 "icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
238 "name" : "cmd",
239 "padding" : "0, 0, 0, 0",
240 "snapOnInput" : true,
241 "startingDirectory" : "%USERPROFILE%",
242 "useAcrylic" : true
243 },
244 {
245 "acrylicOpacity" : 0.5,
246 "closeOnExit" : true,
247 "colorScheme" : "Campbell",
248 "commandline" : "wsl.exe -d Ubuntu",
249 "cursorColor" : "#FFFFFF",
250 "cursorShape" : "bar",
251 "fontFace" : "Cascia Code PL",
252 "fontSize" : 10,
253 "guid" : "{2c4de342-38b7-51cf-b940-2309a097f518}",
254 "historySize" : 9001,
255 "icon" : "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png",
256 "name" : "Ubuntu",
257 "padding" : "0, 0, 0, 0",
258 "snapOnInput" : true,
259 "useAcrylic" : false
260 },
261 {
262 "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
263 "hidden": false,
264 "name": "Azure Cloud Shell",
265 "source": "Windows.Terminal.Azure"
266 },
267 {
268 "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
269 "hidden": false,
270 "name": "PowerShell",
271 "source": "Windows.Terminal.PowershellCore",
272 "acrylicOpacity" : 0.75,
273 "closeOnExit" : true,
274 "colorScheme" : "Campbell",
275 "cursorColor" : "#FFFFFF",
276 "cursorShape" : "bar",
277 "fontFace": "Cascadia Code PL",
278 "fontSize" : 10,
279 "padding" : "0, 0, 0, 0",
280 "snapOnInput" : true,
281 "startingDirectory" : "%USERPROFILE%",
282 "useAcrylic" : true
283 }
284 ],
285 "schemes" :
286 [
287 {
288 "name": "Framer",
289 "black": "#141414",
290 "red": "#ff5555",
291 "green": "#98ec65",
292 "yellow": "#ffcc33",
293 "blue": "#00aaff",
294 "purple": "#aa88ff",
295 "cyan": "#88ddff",
296 "white": "#cccccc",
297 "brightBlack": "#414141",
298 "brightRed": "#ff8888",
299 "brightGreen": "#b6f292",
300 "brightYellow": "#ffd966",
301 "brightBlue": "#33bbff",
302 "brightPurple": "#cebbff",
303 "brightCyan": "#bbecff",
304 "brightWhite": "#ffffff",
305 "background": "#111111",
306 "foreground": "#777777"
307 },{
308 "background" : "#0C0C0C",
309 "black" : "#0C0C0C",
310 "blue" : "#0037DA",
311 "brightBlack" : "#767676",
312 "brightBlue" : "#3B78FF",
313 "brightCyan" : "#61D6D6",
314 "brightGreen" : "#16C60C",
315 "brightPurple" : "#B4009E",
316 "brightRed" : "#E74856",
317 "brightWhite" : "#F2F2F2",
318 "brightYellow" : "#F9F1A5",
319 "cyan" : "#3A96DD",
320 "foreground" : "#CCCCCC",
321 "green" : "#13A10E",
322 "name" : "Campbell",
323 "purple" : "#881798",
324 "red" : "#C50F1F",
325 "white" : "#CCCCCC",
326 "yellow" : "#C19C00"
327 },
328 {
329 "background" : "#282C34",
330 "black" : "#282C34",
331 "blue" : "#61AFEF",
332 "brightBlack" : "#5A6374",
333 "brightBlue" : "#61AFEF",
334 "brightCyan" : "#56B6C2",
335 "brightGreen" : "#98C379",
336 "brightPurple" : "#C678DD",
337 "brightRed" : "#E06C75",
338 "brightWhite" : "#DCDFE4",
339 "brightYellow" : "#E5C07B",
340 "cyan" : "#56B6C2",
341 "foreground" : "#DCDFE4",
342 "green" : "#98C379",
343 "name" : "One Half Dark",
344 "purple" : "#C678DD",
345 "red" : "#E06C75",
346 "white" : "#DCDFE4",
347 "yellow" : "#E5C07B"
348 },
349 {
350 "background" : "#FAFAFA",
351 "black" : "#383A42",
352 "blue" : "#0184BC",
353 "brightBlack" : "#4F525D",
354 "brightBlue" : "#61AFEF",
355 "brightCyan" : "#56B5C1",
356 "brightGreen" : "#98C379",
357 "brightPurple" : "#C577DD",
358 "brightRed" : "#DF6C75",
359 "brightWhite" : "#FFFFFF",
360 "brightYellow" : "#E4C07A",
361 "cyan" : "#0997B3",
362 "foreground" : "#383A42",
363 "green" : "#50A14F",
364 "name" : "One Half Light",
365 "purple" : "#A626A4",
366 "red" : "#E45649",
367 "white" : "#FAFAFA",
368 "yellow" : "#C18301"
369 },
370 {
371 "background" : "#002B36",
372 "black" : "#073642",
373 "blue" : "#268BD2",
374 "brightBlack" : "#002B36",
375 "brightBlue" : "#839496",
376 "brightCyan" : "#93A1A1",
377 "brightGreen" : "#586E75",
378 "brightPurple" : "#6C71C4",
379 "brightRed" : "#CB4B16",
380 "brightWhite" : "#FDF6E3",
381 "brightYellow" : "#657B83",
382 "cyan" : "#2AA198",
383 "foreground" : "#839496",
384 "green" : "#859900",
385 "name" : "Solarized Dark",
386 "purple" : "#D33682",
387 "red" : "#DC322F",
388 "white" : "#EEE8D5",
389 "yellow" : "#B58900"
390 },
391 {
392 "background" : "#FDF6E3",
393 "black" : "#073642",
394 "blue" : "#268BD2",
395 "brightBlack" : "#002B36",
396 "brightBlue" : "#839496",
397 "brightCyan" : "#93A1A1",
398 "brightGreen" : "#586E75",
399 "brightPurple" : "#6C71C4",
400 "brightRed" : "#CB4B16",
401 "brightWhite" : "#FDF6E3",
402 "brightYellow" : "#657B83",
403 "cyan" : "#2AA198",
404 "foreground" : "#657B83",
405 "green" : "#859900",
406 "name" : "Solarized Light",
407 "purple" : "#D33682",
408 "red" : "#DC322F",
409 "white" : "#EEE8D5",
410 "yellow" : "#B58900"
411 }
412 ]
413}

The configuration will be automatically refreshed in the Terminal as soon as the file has been saved.

After the Terminal settings have been modified it’s time to improve the PowerShell profile.

The profile for the traditional Windows PowerShell can be found here: C:\Users\YOURUSERNAME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

The profile for PowerShell Core can be found here: C:\Users\YOURUSERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

Depending on which PowerShell you use ( maybe both ) you can place the content into the files. I typically open the files with VSCode from the PowerShell by typing

1code $profile

I added a function to automatically load or install modules depending on their installation state. If a module is missing my system tries to install the missing module from PSGallery.

My PowerShell profile:

1function Add-Module ($m) {
2 if (Get-Module $m) {
3 Write-Output "Module $m is already imported."
4 }
5 else {
6 try {
7 Import-Module $m -ErrorAction Stop
8 }
9 catch {
10 Write-Output "Module $m not found locally or error while importing"
11 # Find the module online
12 if (Find-Module -Name $m | Where-Object { $_.Name -eq $m }) {
13 Install-Module -Name $m -Force -Verbose -Scope CurrentUser -AllowClobber
14 Import-Module $m -Verbose
15 }
16 else {
17 Write-Output "Module $m not available"
18 }
19 }
20 }
21}
22
23function checkFont($font) {
24 [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
25 $families = (New-Object System.Drawing.Text.InstalledFontCollection).Families
26 $families -contains $font
27}
28
29Add-Module "posh-git"
30Add-Module "oh-my-posh"
31# cd which remembers your history https://www.powershellgallery.com/packages/z/
32Add-Module "z"
33# Set the posh theme
34Set-Theme Paradox
35
36# Nice colors for listings
37Add-Module "Get-ChildItemColor"
38# Set l and ls alias to use the new Get-ChildItemColor cmdlets
39Set-Alias l Get-ChildItemColor -Option AllScope
40Set-Alias ls Get-ChildItemColorFormatWide -Option AllScope
41# Remove the Username from the terminal
42$DefaultUser = $env:USERNAME
43
44# Setting for git posh
45$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true
46
47# Chocolatey profile activates tab completion for powershell
48$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
49if (Test-Path($ChocolateyProfile)) {
50 Import-Module "$ChocolateyProfile"
51}
52
53# Command to jump to my dev directory
54function dev { Set-Location ~/Development }
55
56# Java HOME for Android Development ( only if you need it )
57$env:JAVA_HOME = "C:\Program Files\Android\Android Studio\jre\"
58# Adnroid HOME
59$env:ANDROID_HOME = $HOME + "\AppData\Local\Android\Sdk\"
60
61# NVM path and path to the android tools
62$env:Path = $env:Path + ";" + $env:NVM_HOME + ";" + $env:NVM_SYMLINK + ";" + $env:Android_Home + "\tools;" + $env:Android_Home + "\platform-tools"
63# Path to kubectl config
64$env:path += $HOME + "\.azure-kubectl"
65
66# only enter a single character to use git or kubectl
67Set-Alias -Name g -Value "git" -Description "git"
68Set-Alias -Name k -Value "kubectl" -Description "Kubernetes CLI"

After modifying the Powershell profile file you should close all open instances of Powershell and the Windows Terminal.

If you open the Terminal and a Powershell Tab the described Powershell Modules should be installed and activated automatically.

Additional Ressources

A website with some copy-paste configuration for Windows Terminal themes: https://atomcorp.github.io/themes/

More articles from Dominic Böttger

Securely fight COVID-19 in a Windows Sandbox

A simple script which installs the Folding@Home client into a Windows Sandbox.

April 12th, 2020 · 1 min read

Send templated AWS SES emails with PowerShell

A brief description on how a SES mail template can be stored and send with the AWS (Amazon Web Services) Powershell module.

March 31st, 2020 · 1 min read
© 2020 Dominic Böttger
Link to $https://twitter.com/dboettgerLink to $https://github.com/dominicboettgerLink to $https://www.linkedin.com/in/dominic-b%C3%B6ttger-74952a138/