Using Bash on Windows 10

Published on

If you're looking to use Bash on Windows in 2020, you're likely to see a lot of articles about Windows Subsystem for Linux (WSL) and the second version that has recently been released. This isn't about that.

You see, coming from Mac and Linux backgrounds I have always been underwhelmed by the Windows terminals. For a long time now we've been able to use "Git Bash" which works fine in terms of running the same commands that I've been used to for years. But it has never felt nice to use, the keybindings are all odd and the customisation is limited.

So I was quite excited when they announced the new Windows Terminal (which you can download from the Windows Store). When I first tried it, I could see it was nicer to use but quickly realised most articles explained how to use it for Powershell or WSL. I'm sure WSL is brilliant but it's better for doing Node.js kind of work, I use my Mac whenever I do that. So I gave up and continued using Git Bash with the mild frustration I've always experienced with it.


That was until I got a tweet from Rich Turner explaining how to add a new profile. Now, I'm sure I did the exact steps he mentioned when I first tried... I know I got bash running in some way but it felt very hacky and not good. I don't know what I did originally but I do know how I got it working well. I haven't got it set up yet with all the same customisations as I have on Mac but it does now work well as a basic terminal without any of the frustrations I've always had when using Windows for development work.

Adding the profile

To add Bash to the Windows Terminal you need to add a profile (essentially an object to an array) in the settings JSON file. I followed a Stack Overflow answer but will briefly note how to do it here.

  • Note: You need Git for Windows installed. This uses the same shell as Git Bash but with a different terminal.
  • From within Windows Terminal, press ctrl + , (or the triangular menu at the top then Settings). This will open a text editor showing the settings JSON file.

  • There will be a profiles object with an array called list inside it. You will want to add the profile for Bash inside this array.

  • Below is the profile I'm currently using, one day I will add more customisation and find a good colour scheme but it does the job for now. It's almost identical to the one from the Stack Overflow answer, but I've removed the transparency. The two most important parts are the guid which must be unique (can be random, but has to be unique within the list) and the commandline which is where bash.exe is set.

  
    {
        "guid": "{00000000-0000-0000-ba54-000000000002}",
        "closeOnExit": true,
        "colorScheme": "Campbell",
        "commandline": "\"%PROGRAMFILES%\\git\\usr\\bin\\bash.exe\" -i -l",
        "cursorColor": "#FFFFFF",
        "cursorShape": "bar",
        "fontFace": "Consolas",
        "fontSize": 10,
        "historySize": 9001,
        "icon": "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
        "name": "Bash",
        "padding": "5, 5, 5, 5",
        "snapOnInput": true,
        "startingDirectory": "%USERPROFILE%"
      }
  

Default profile

I'm sure PowerShell is great, but it's not my shell of choice (on Mac I use zsh). Thankfully with Windows Terminal it allows us to set whichever shell you want by setting the defaultProfile at the root level of the settings JSON to be the GUID of your chosen profile. Given it is default profile not default shell, this could be taken further to have multiple customisations with one as your default.

  
    "defaultProfile": "{00000000-0000-0000-ba54-000000000002}",
  

Keybindings

It's really useful to be able to define your own keybindings, especially when going between two Operating Systems. I have kept it very light for now, so I've only changed settings to fix the frustrations I've had in the past with terminals on Windows. I'm sure there's far more interesting things that can be done!

Copy and Paste

When I started using Windows Terminal (and indeed the first time I tried and failed to use it) one of my annoyances was the lack of sensible copy/paste keybindings. I am so used to Mac having cmd + c and cmd + v within the terminal that it's always been my main frustration with Git Bash it has weird bindings.

I was able to finally fix these in the settings file for Windows Terminal. But it turns out that recently version 1.0 was released, which has these as a default.

So chances are this is no longer an issue for people. But for anyone that is still on an older version, you can add these within the keybindings array in the settings file:

  
    {
        "command": {
          "action": "copy",
          "singleLine": false
        },
        "keys": "ctrl+c"
      },
      {
        "command": "paste",
        "keys": "ctrl+v"
      }
  

New tab

It's really nice that Windows Terminal has tabs... but it is quite weird that the default keybinding for new tab is ctrl + shift + t. Maybe it fits in better with shortcuts that Windows power users already use but for me I kept pressing the wrong buttons. I work mostly in the browser, so I've copied the new tab shortcut I use all the time in browsers ctrl + t. Again, it's added to the keybindings array in the settings file.

  
    // Open New Tab
    {
      "command": "newTab",
      "keys": "ctrl+t"
    }
  

Verdict

The purpose of a terminal is to barely notice it exists. It should just be the way you talk to the computer at one of the lowest levels possible. I'm happy that with these adjustments to Windows Terminal (and with even less required for the latest version) there is now a good way to use Bash on Windows. The old ways were fine but from puTTY to Git Bash, it never felt the same as using Mac or Linux. Now it feels close enough and the WSL exists too so that's brilliant but for normal day-to-day activities like using Git it now just gets out of the way. The frustration is gone, I can get on with stuff now.