This post gives some notes on ways to create a Unix-like command line experience on Windows, without using a virtual machine like VMWare or a quasi-virtual machine like Cygwin.
Finding Windows ports of Unix utilities is easy. The harder part is finding a shell that behaves as expected. (Of course “as expected” depends on your expectations!)
I’d recommend the combination of Gow and Clink for most people. If you’re an Emacs power user you might like Eshell.
The built-in command line on Windows is
cmd. It’s sometimes called the “DOS prompt” though that’s misleading. DOS died two decades ago and the
cmd shell has improved quite a bit since then.
cmd has some features you might not expect, such as
popd. However, I don’t believe it has anything analogous to
dirs to let you see the directory stack.
PowerShell is a very sophisticated scripting environment, but the interactive shell itself (e.g. command editing functionality) is basically
cmd. (I haven’t kept up with PowerShell and that may have changed.) This means that writing a PowerShell script is completely different from writing a batch file, but the experience of navigating the command line is essentially the same as
You can run shells inside Emacs. By default,
M-x shell brings up a
cmd prompt inside an Emacs buffer. You can also use Emacs’ own shell with the command
Eshell is a shell implemented in Emacs Lisp. Using Eshell is very similar across platforms. On a fresh Windows machine, with nothing like Gow installed, Eshell provides some of the most common Unix utilities. You can use the
which command to see whether you’re using a native executable or Emacs Lisp code. For example, if you type
which ls into Eshell, you get the response
eshell/ls is a compiled Lisp function in `em-ls.el'
The primary benefit of Eshell is that provides integration with Emacs. As the documentation says
Eshell is not a replacement for system shells such as
zsh. Use Eshell when you want to move text between Emacs and external processes …
Eshell does not provide some of the command editing features you might expect from
bash. But the reason for this is clear: if you’re inside Emacs, you’d want to use the full power of Emacs editing, not the stripped-down editing features of a command line. For example, you cannot use
^foo^bar to replace
bar in the previous command. Instead, you could retrieve the previous command and edit it just as you edit any other line inside Emacs.
bash you can use
!^ to recall the first argument of the previous command and
$_ instead. Many of the other
bash shortcuts that begin with
! work as expected:
!-3, etc. Directory navigation commands like
popd work as in
Gow comes with a
bash shell, a Windows command line program that creates a
bash-like environment. I haven’t had much experience with it, but it seems to be a faithful bash implementation with few compromises for Windows, for better and for worse. For example, it doesn’t understand backslashes as directory separators.
Clink is not a shell per se but an extension to
cmd. It adds the functionality of the Gnu
readline library to the Windows command line and so you can use all the Emacs-like editing commands that you can with
bash: Control-a to move to the beginning of a line, Control-k to delete the rest of a line, etc.
Clink also gives you Windows-like behavior that Windows itself doesn’t provide, such as being able to paste text onto the command line with Control-v.
I’ve heard that Clink will work with PowerShell, but I was not able to make it work.
The command editing and history shortcuts beginning with
! mentioned above all work with Clink, as do substitutions like
In my opinion, the combination of Gow and Clink gives a good compromise between a Windows and Unix work environment. And if you’re running Windows, a compromise is probably what you want. Otherwise, simply run a (possibly virtual) Linux machine. Attempts to make Windows too Unix-like run down an uncanny valley where it’s easy to waste a lot of time.