Windows, Chocolatey, Git Bash, Ssh-agent and Visual Studio Code

Published

I'm back and forth with IDE's. The last one I used is PyCharm. I like PyCharm, but when I need to do something that's not in Python, I need to reach for a good ol fashioned text editor. Thankfully we have tools like Atom and my current go-to, Visual Studio Code.

Spoiled by brew and package managers in general, I use Chocolatey because I'm on Windows and it's freaking great.

choco install -y vscode git docker docker-machine

Note that installing docker here doesn't install docker-for-windows, just the command line tools for dealing with Docker daemons. Docker-machine is what I use instead of Docker-for-windows, because I occasionally still use Vagrant and don't want to turn off and on Hyper-V. Also Docker-for-windows now requires a login to download and there's some telemetry stuff you can't turn off and I'm wacky and paranoid.

My private keys are passphrase encrypted, so what I have in my ~/.bash_profile is

alias ssh-agent='ssh-agent > ~/.ssh_agent; chmod 700 ~/.ssh_agent; source ~/.ssh_agent'

if [ -f ~/.ssh_agent ]; then
    source ~/.ssh_agent
fi

This is a bit of a security problem as the output of ssh-agent is kind of privileged, but for me the productivity benefits outweight the cons. Maybe just remember to kill the agent when you leave your computer.

What's nice about this is that if you launch Code from your terminal, it inherits all the environment variables, so if you do something like:

bash $ ssh-agent  # or $(eval ssh-agent) if you're not using an alias
bash $ ssh-add
Enter passphrase for ~/.ssh/id_rsa...
bash $ eval $(docker-machine env)
bash $ code

Then Code will be aware of your SSH agent, Docker settings and anything else you might have. Git pushes and pulls will work perfectly and if you're pointed to a remote Docker host, it will appear in Code's Docker extension.

Powershell is better than previous incarnations of the Windows shell, but it ain't no Bash terminal. Installing git installs git-bash, which includes Msys-Bash, which in my opinion the best terminal available on Windows.

Also if you don't already use Code's built in Git source control features like the side by side diffs, I highly recommend checking it out. I used to have a bunch of uncommitted changes to some of my local projects because I was too lazy to shell in and git diff every file. Having it in the editor is a major productivity boost.