• Stars
    star
    384
  • Rank 111,726 (Top 3 %)
  • Language
    PowerShell
  • Created over 8 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mike's Powershell Profile (and how to set up Windows console if you've been using *nix for 20 years)

Mike's Powershell profile: how to set up a terminal in Windows if you've been using *nix for 20 years

Heya. I've been using bash for about two decades before getting into Powershell. I'm a *nix person. I've worked at both Red Hat in the early days, IBM's dedicated Linux team, and a bunch of other places working with *nix as an sysadmin, SRE, Architect, and CTO. I now develop node and TypeScript while trying to make verifying companies for EV HTTPS less painful at CertSimple.

If you come from a Linux or Unix background, and want to use Powershell properly, this is the right place.

  • Better defaults, like UTF-8 output, long history, better tab completion, adding missing drives for registry hives, and a nice short prompt using the '~' character. See defaults.ps1
  • Implementations of popular Unix commands. See unix.ps1
  • Useful commands for software development using git. See development.ps1
  • Useful commands and settings for node development. See node.ps1
  • Useful commands for crypto, including converting between different crypto file types, checking if private keys and certs match, etc. See openssl.ps1
  • Config files for Windows Terminal, Terminus, and other modern Windows terminals.

The profile code itself contains useful implementations of common patterns - eg, installing packages, reading the registry, interacting with files and processes. Learning the things required to make a profile you're happy with is a great way to get comfortable with Powershell.

The details below are minimal, but the names of most commands make things fairly obvious.

Prerequisities for any *nix user who wants to use Powershell

This is what I install on any Windows 10 box.

Powershell Core 6.2

Powershell Core 6.2 has a number of useful bits, but the main thing is it starts way faster than Powershell 5, so there's less lag when you open a new tab.

Powershell 6.2 includes PSReadline, which provides history with up/down arrows, ctrl left and right to move between words, and other useful keybindings you'll know from bash.

Trust PSGallery

To allow you to install items without further prompts:

Set-PSRepository -name PSGallery -InstallationPolicy Trusted

For less, Add-PAthVariable and a bunch of other useful commands that should be there out of the box

Get the Powershell Community Extensions. Run:

Install-Module Pscx -Scope CurrentUser

AllowClobber is needed due to this bug

For 'Remove-ItemSafely' - ie, trashing files from the command line

Run:

Install-Module -Name Recycle -Scope CurrentUser

For a decent, tabbed terminal

Tabbed terminals that work now

The terminals below all support:

  • Tabs
  • Readline
  • Right click paste
  • Copy on select

....and all the usual things you expect from any decent terminal emulator. I use Windows Terminal, which is in Preview right now, but usable as a day to day terminal. Fluent Terminal also works great out of the box.

  • Microsoft's official Windows Terminal. Open the Settings file, enable copyOnSelect and change "commandline": "C:\\Program Files\\PowerShell\\6\\pwsh.exe -nologo", - the nologo makes Powershell skip some boring startup messages.
  • FluentTerminal is a native Windows 10 terminal that feels as if Microsoft had written it. It requires minimal configuration (just to add Powershell 6 to the profiles), has all the features you'd expect, and is fast.
  • Terminus works great. Tweaking colors, keyboard shortcuts etc is easy via the menus, and my settings file is included if you just want my config.
  • Hyper Install Hyper 3 and modify the config to set:
shell: "C:\\Program Files\\PowerShell\\6\\pwsh.exe",

and

shellArgs: [],

To work around issues with arrow keys you'll also need to click Edit, Preferences, find keymaps, and replace the existing entries with one below:

  keymaps: {
    // Example
    // 'window:devtools': 'cmd+alt+o',
    "tab:new": "ctrl+t",
    // Also known as 'close tab'
    "pane:close": "ctrl+w",
    // This is a poor default, as these are used to navigate between words
    // "tab:next": ["ctrl+right"],
    // "tab:prev": ["ctrl+left"],
    // Bug workaround for https://github.com/zeit/hyper/issues/2873
    "editor:movePreviousWord": "",
    "editor:moveNextWord": ""
  }

Minimal terminals

The following apps are console window only - they don't provide tabs, graphical config tools, etc. You can add an app like Groupy to them to make a tabbed terminal, but they require more setup than just using Terminus.

  • The inbuilt Powershell 6 terminal
  • Alacritty is fast. You'll also need to have the following in AppData\Roaming\alacritty\alacritty.yml
    shell:
        program: 'C:\Program Files\PowerShell\6\pwsh.exe'
   
    enable_experimental_conpty_backend: true

Terminal apps that don't yet work on Windows

The apps below all plan on having Windows support in future, but don't yet properly work at the time of writing. There are links to the tracking bugs below.

Not a terminal

cmder's website makes it seems like it's a new terminal, but cmder is just ConEmu and some additional things you may already have installed and some other things you don't want (like cmd tools).

Old-style Win32 apps

These have the 'everything at once' UI design of older Windows operating systems.

  • ConEmu works, but has some contrast issues which make it hard to see the open tab, and is hampered by its author's desire for Windows XP support.
  • ConsoleZ is an updated version of the now-unmaintained Console2.

To pick a color scheme / theme

Browse iterm2colorschemes.com and download the equivalent named Windows Terminal file from their Windows Terminal color schemes. Open Settings and paste it into the schemes section, then select that scheme name for the profile you want to use it with in profiles.

Terminus has it's own color schemes, just open Settings > Appearance > Color Scheme and pick one (or use my config file).

ColorTool also supports importing the well know .itermcolors format. Download ColorTool from Microsoft's GitHub. You can edit an .itermcolors file using terminal.sexy.

Run:

./colortool -b color-scheme.itermcolors

For OpenSSH

OpenSSH now comes with Windows. Settings -> Manage Optional Features -> OpenSSH client.

For a nice prompt

By default $prompt is a minimal, bash-style prompt with a truncated path. If you're feeling fancier, you can install oh-my-posh.

For OpenSSL (if you need it)

Personally I use OpenSSL for viewing private keys, pubkeys, certificates, and other TLS/PKI work. Unless you do the same you probably don't need OpenSSL.

The Windows version of OpenSSH uses Windows CryptoAPI rather than OpenSSL, so if you want to add OpenSSL, you'll have to install it.

Use this up to date, secure Windows OpenSSL build.

For host, dig and other DNS tools

Download Bind 9 for Windows. Extract the zip and run BINDinstall.exe as Administrator. Select 'Tools Only'.

If you want a better 'select-string' (aka grep)

The Find-String module adds match highlighting and other fun things. For me the inbuilt select-string is enough.

Install-Module -Name Find-String -Scope CurrentUser

If you use node

Start Powershell 5 as admin and run:

npm install -g windows-build-tools

Minimum Powershell concepts to learn before you rant about how much you hate Powershell

These come with powershell. If you don't know them you're the equivalent of someone who doesn't know grep ranting about how "Unix is like DOS". That might be painful to hear but it's true.

select (also called select-object) - select the fields you want on an object

get-member - show the properties and methods of an object

get-itemproperty - show the properties of registry objects (ls only shows children)

where (also called where-object) - choose items matching some criteria.

get-help some-command -examples - every command has examples.

How does Powershell actually differ from bash, day-to-day?

Here's a real comparison: a bash script used to find a compromised node module a little while ago:

find . -type d -name "eslint-scope" -print0 | xargs -n 1 -0 -I % sh -c "(cat %/package.json | npx json version) && echo '(at %)'"

Here's a Powershell version. This is written using Unix aliases as that's what folk are familiar with, though it's generally considered better to use the full names in your scripts:

$results = @{} 
ls -recurse -filter "eslint-scope" | foreach { 
	$file = "${PSItem}\package.json" 
	$version = cat $file | convertfrom-json | select -ExpandProperty version 
	$results.Add($file,$version) } 
echo $results | format-list

You might prefer one or the other, but the important difference:

  • Powershell has real objects. We're creating a hashmap of $file,$version pairs.
  • In Powershell we select the keys whose values we want, rather than scraping with regexs
  • Powershell seperates content from presentation, so we can format our $results however we want
  • Powershell has inbuilt tools to parse JSON (and CSV, and Excel, and other common formats). It can make them too.

Why Windows filesystem is slow

Filesystem access under Windows is undoubtably slower than ext3/4 for most tasks. See microsoft/WSL#873 (comment) for more details about why and some performance hints to speed things up. There's also plans to improve things in future.

Included commands

Stuff that should be there out of the box

edit - edits a file (using VSCode insiders, but modify as you please)

open - open a file using associated app

settings - the Windows Settings app

explorer - file explorer

File management

expand-archive - also called unzip

find-file

show-links

OS management

reboot

get-windows-build

disable-windows-search - Windows Search Indexer doesn't handle filesystems with lots of small files - the 'Windows Search Indexer' process will kick in when you're working, and make interactive so slow you'll be waiting for your keyboard strokes to appear on screen. I've discussed this with Rich Tuner from Microsoft who says the search team are working on fixing this, but right now I suggest you disable the indexer.

You can still search for files without the Indexer, it'll just not using the indexes, so take a little longer. You can also just use find-file included here.

get-serial-number

Unix like commands

grep

grepv

df

sed

edit-recursive - sed but recursive

fuser

pkill

pgrep

touch

file

sudo - note command after sudo must be quoted

uptime

cut

export

ln

pstree

which

find

Powershell stuff

prompt - a nice Unixlike prompt with ~ style truncation for the home directory

edit-powershell-profile

update-powershell-profile - re-run your profile

set-title - set the window title

get-path - get the PATH, one item per line

Development

get-git-ignored

get-git-untracked

gg - A git grep Alias

yarn - Yarn wrapper with yarn ls re-added, since I hate typing yarn list

sourcetree - SourceTree

Crypto

read-certificate

read-csr

read-rsa-key

read-rsa-key

read-ecc-key

read-pkcs12

test-openssl-client

convert-pem-to-p12

convert-p12-to-pem

convert-crt-to-pem

show-rsa-certificate-modulus

show-ecdsa-certificate-ppv-and-curve

show-rsa-key-modulus

show-ecc-key-ppv-and-curve

show-rsa-csr-modulus

protect-file

unprotect-file

convert-key-to-hpkp-pin

convert-website-to-hpkp-pin

More Repositories

1

python-docx

Reads, queries and modifies Microsoft Word 2007/2008 docx files.
Python
1,068
star
2

compact-wsl2-disk

A small script for Windows 10 Home users to compact their WSL2 disks
PowerShell
233
star
3

outdated-browser-rework

Detects outdated browsers and advises users to upgrade to a new version. Handles mobile devices!
JavaScript
224
star
4

how-to-install-a-linux-development-environment-on-windows

How to install a Linux development environment on Windows using Ubuntu and WSL2
117
star
5

agave

Cleaner, simpler JavaScript for ES6
JavaScript
115
star
6

serverless-starter-kit

A fulllstack serverless app using TypeScript, Svelte and Architect Serverless
TypeScript
67
star
7

stickers

Various stickers I made, printed and gave away at jsconf 2015
63
star
8

whois-json

Whois with results in actual, structured, camelCased JavaScript!
JavaScript
62
star
9

styleselect

Simple, standalone styling for select boxes in modern browsers.
JavaScript
37
star
10

dynamic-template

Simple dynamic ES6 templates
JavaScript
22
star
11

eyes

Removes eyes from the internet
JavaScript
15
star
12

sorts

JavaScript
15
star
13

eslint-plugin-must-use-await

Flags use of callback functions and .then(), for users of ES2017's async/await
JavaScript
11
star
14

kind.js

Return the kind of a JS object (the same as what a human would).
JavaScript
9
star
15

amps-in-the-trunk

Transform HTML directly to Google AMP HTML
JavaScript
8
star
16

companies-house

A JavaScript client for the Companies House API
JavaScript
7
star
17

pyfilter

Python client for pifilter adult image detection service (www.pifilter.com). Useful for helping automate moderation on public forums.
7
star
18

sass-npm

Import SASS files from npm modules
JavaScript
7
star
19

express-geoip

Express 4 middleware to add req.countryCode, which is the ISO alpha 2 country code, to requests.
JavaScript
6
star
20

is-gmail-account-valid

Find out if a gmail address is used or not
JavaScript
5
star
21

boilerplatejs

JavaScript
4
star
22

pr-chart

Simple AWS SAM / TypeScript / Arc / Svelte app
TypeScript
3
star
23

aoftmurmurkeys

Start and pause A Soft Murmur using the F5 key on your keyboard.
JavaScript
3
star
24

japanese_mayonnaise

Minimal Chrome extension. Removes animated notification area from Google search results.
JavaScript
2
star
25

epilepsy

Make your own Enter the Void style credits. With apologies to Tom Kan.
JavaScript
2
star
26

meatspace-enterprise-edition

JavaScript
2
star
27

devils_pie

A tool to solve the 10 Fast Finger Speedtest http://speedtest.10fastfingers.com/
JavaScript
2
star
28

ringespiel.js

A modern carousel for JQuery
JavaScript
2
star
29

express-middleware-to-async

Express to Arc middleware converter (Experimental)
JavaScript
2
star
30

jquery-html5-validity

JavaScript
2
star
31

imeveryone

Realtime anonymous communication platform
Python
2
star
32

solana-basics-for-everyone

The Keynote Presentation from my Solana Basics for Everyone presentation at Breakpoint 2023.
1
star
33

burn-everything-down

JavaScript
1
star
34

rolex

A better 'watch'
JavaScript
1
star
35

scalpels-and-aks

JavaScript
1
star
36

dotfiles

Mike's dotfiles.
Shell
1
star
37

staring_and_slurping

Starts/stops Soundcloud using the F5 key on your Mac
JavaScript
1
star
38

chrome-bluetooth

Chrome Bluetooth test
JavaScript
1
star
39

emptiness.js

JavaScript
1
star
40

formsed

A simple Chrome extension to quickly search/replace form data automatically when matched URLs are hit.
JavaScript
1
star
41

boring-config

Load a CSON config file
JavaScript
1
star
42

goodbye_horses

High performance CMS
JavaScript
1
star
43

london-javascript-events

List of all JavaScript events in London
1
star
44

minimal-messaging-extension

A minimal manifest v3 extension using chrome.runtime.sendMessage()
JavaScript
1
star
45

nodeplayground

A personal scratch playground for testing ideas in Node JS
1
star
46

quaderno-server

Helps calculate JSON web tokens (JWTs) for one-off charges in Quaderno.
JavaScript
1
star
47

rejectjs2013

Welcome our new ES5 Overlords
JavaScript
1
star
48

goodbye-horses

JavaScript
1
star
49

guetta

Adds additional David Guetta to websites
CoffeeScript
1
star