tl;dr

  • Arrow keys may not work in GIT Bash under Windows Terminal

  • ssh-agent may not work as expected (login shell vs. interactive shell)


Many of us are enjoying using Windows Terminal. But just to put things into perspective: Windows Terminal doesn't revolutionize the way you'll use terminals in the future. Most of the excitement around Windows Terminal is because of:

  • Graphics - Windows Terminal supports some pretty graphics options like acrylic backgrounds and colors and themes
  • Text Rendering - Windows Terminal can display emoticons, icons and other exotic glyphs
  • Tabs - You may open multiple tabs - each with their own shell in the same Windows Terminal window. You've got an easy way to chose what style terminal to open
  • Frames - You may now subdivide your Windows Terminal screen into vertical and horizontal panes. This effectively open multiple shells in the same tab

Here's the official release document. These features are really nice for Windows but, honestly, they've been around in other terminals on other systems for a very long time. There's no new feature in Windows Terminal that has simply turned the terminal universe on its head. Windows Terminal just modernizes what terminals have been in the Windows world - not the whole world.

Nevertheless, I've enjoyed seeing fonts rendered and scaled so smoothly! It is quite pleasant to work in.

However, there are some 'gotchas' that you should know about - especially if you use GIT Bash as your main portal into you Linux world.

Gotcha 1: "Hey! My arrow keys aren't working!"

Yes, you may notice that your arrow keys don't work as you've come to expect anymore.

You may notice this when you open VIM for the first time. If you've gotten used to using arrow keys in VIM (purists are already laughing at those of us who do) you'll see that your precious arrow keys cannot be used for navigation in VIM when using GIT Bash by default.

To help you get around initially you should get used to the traditional way of navigating VIM: the H, J, K, and L keys.

  • H : move one character LEFT
  • J : move one line DOWN
  • K : move one line UP
  • L : move one character RIGHT

At least that gets us started. In addition, you also have the CTRL+keystroke option to navigate while still using the arrow keys: ctrl + arrow_key. So, typing: ctrl + up_arrow will move your cursor up one line.

Now, you can navigate enough to make the necessary edits to enable arrow keys!

When I come up with a better solution to this issue I'll update this article.

Gotcha 2: "Hey! ssh-agent doesn't work anymore!"

Many of us have used GIT's documentation to enable ssh-agent as soon as we start GIT Bash. ssh-agent lets us to enter our passphrase once at the beginning of our shell session. After that, our keys remain open and are automatically used when we SSH into other machines.

If you were using GIT Bash before migrating to Windows Terminal, you may have followed the documentation's first suggestion to put the following code in your ~/.profile file:

env=~/.ssh/agent.env

agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }

agent_load_env

# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi

unset env

I did that and had no trouble using ssh-agent in GIT Bash. However, when you use Windows Terminal with a profile for GIT Bash the above does not work.

There are two ways to correct this issue. Either:

  1. set Bash to be a login shell
  2. put the ssh-agent directives in the ~/.bashrc file

The reason for this is because the ~/.profile file is the configuration for login shells whereas the ~/.bashrc file is the configuration for interactive shells.

  • ~/.profile : Configuration script for login shells. For example: when you login into the text-console of a machine from another host.
  • ~/.bashrc : Configuration script for interactive shells. For example: opening a terminal on a windowing system in which you've already logged in.

Just think of the ~/.profile script as Bash's login script.

So, if GIT Bash is not configured as a login shell, it will not run the ~/.profile file when it starts. If GIT Bash is configured to run as an interactive shell it runs the ~/.bashrc file.

Setting Bash to be the login shell.

You may change the commandline directive in your Windows Terminal profile for GIT Bash to something like this:

"\"%SystemDrive%\\Program Files\\Git\\bin\\bash.exe\" -i -l"

The critical flags are -i and -l which configure GIT Bash to run as both a login and interactive shell. This causes Bash to read both configuration files.

Moving the ssh-agent code to ~/.bashrc

If you don't want to change your GIT Bash's profile settings in Windows Terminal you should put the ssh-agent code into the ~/.bashrc file, not the ~/.profile file. Once done, ssh-agent works as expected.

Conclusion

Those are a few of the gotchas when starting to use Windows Terminal. As I discover other notable issues and fixes I'll try to document them here.