Making a Windows shell that doesn’t suck

shell-tabs

Over the last 20 years, I’ve had the pleasure of using Unix, Linux, DOS, Windows and OSX. One thing they all had in common was the notion of a “shell” or “command prompt”. One thing they didn’t all have in common was a good command prompt. Yes Windows, I’m looking at you!

Let’s look at a few tools we can string together to make a rockin’ windows shell!

GitHub for Windows should be be “Better Shell for Windows”

I hope I didn’t already loose you. I’m not the biggest fan of GitHub for Windows. In fact I don’t really use the application itself. However, installing it is the easiest way to get Git installed, and some basic shell improvements.

GitHub SSH Authentication. Done!

Assuming you have a GitHub account, the GitHub for Windows installer will install msysgit including all the command line git tools. Then it will create a new SSH key and register it on GitHub. This means all your GitHub authentication is now taken care of. Period. The alternative, making the certs yourself, is annoying and I ain’t got time for that.

Once you get GitHub for Windows installed, you will notice that you can open a shell into a git repo. This by default uses PowerShell, but adds a lot of niceties. Powershell alone is a huge step in the right direction, but I’ve been using some form of *nix and bash since like 1998. I really don’t want to re-learn a whole bunch of commands. Plus, it doesn’t fix the copy/paste issue…

powershell-copy

THIS ISN’T HOW ANYONE WANTS TO SELECT TEST TO COPY!!!

PoshGit. Bam!

But anyway… GitHub for Windows also installs PoshGit for you, so when you are in a git repo, you get some info about that repo on your command prompt. Pretty spiffy!

powershell-poshgit

Unix Commands. On Windows! WAT!

Another interesting feature of the PowerShell window that GitHub for Windows opens is that it has a whole bunch of familiar unix shell commands, like “ls”, “rm”, “more”, etc… Also awesomeis that you can often use unix-style “/” instead of windows-style “\” as a directory separator, and tab-completion will auto-reverse them for you!

The way that GitHub works in all this magic is through a special PowerShell Profile that it generated at install-time. This is locaed at: C:\Users\{your user name}\AppData\Local\GitHub\shell.ps1

One of the initial annoyances is that we only get this when running the shell from GitHub for Windows, but if you just run PowerShell yourself, it is not there. So the next step is to run the GitHub for Windows https://codingwithspike.wordpress.com/wp-admin/edit-tags.php?taxonomy=post_tagpowershell profile all the time. First, we need to enable the running of scripts in PowerShell. So, go ahead and open a PowerShell window as admin (using “Run as Administrator”). Then run the command: Set-ExecutionPolicy Unrestricted (Warning: this has security implications!). If you don’t already have a PowerShell profile created for yourself, then open your text editor of choice and create a file named: C:\Users\{your user name}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 then add these lines to the file:

. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
. $env:github_posh_git\profile.example.ps1

These two commands will run the same setup that GitHub for Windows would have run. So now your PowerShell window gets all the goodies every time you run it!

Console2 brings the bacon!

Well things are certainly improving, but there are still some things that would be nice to have. I’d like multiple console windows in tabs, and really REALLY want to be able to copy and paste text in a sane way. Console2 is the answer! Give it a download and extract the files.

After extracting, run “console.exe” then open the “Edit | Settings…” menu, and go to town setting up your new console!

In the main “Console” settings window, set the “shell” command to %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe which will run PowerShell instead of the old DOS style cmd.exe as the shell, including all the cool stuff from GitHub for Windows that we included through the profile. However, there is a weird extra step here. If you re-open command.exe with PowerShell set as the shell, you will get an error something like: “Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because running scripts is disabled on this system.” You will actually need to re-run console.exe as Admin, and run Set-ExecutionPolicy Unrestricted once again. Then close and re-open again as a non-admin, and things will start to work.

console2-settings1

I also highly recommend going into the “Hotkeys” section of the Console2 settings window and making “Ctrl-C” and “Ctrl-V” do copy/paste (YES!!!)

console2-settings2

These changes are really nice for me because I get some of the power-features of PowerShell, plus the familiar commands of unix/bash. Plus tabs for having several command windows open at once. When working with grunt and git and a lot of other command line tools all day, this is invaluable.

Advertisements
Posted in Windows
One comment on “Making a Windows shell that doesn’t suck
  1. Yabuya Ishbak says:

    Have you tried the Portable console emulator for Windows (Cmder) http://cmder.net/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

CodingWithSpike is Jeff Valore. A professional software engineer, focused on JavaScript, Web Development, C# and the Microsoft stack. Jeff is currently a Software Engineer at Virtual Hold Technologies.


I am also a Pluralsight author. Check out my courses!

%d bloggers like this: