Running scripts in Atom editor on Windows under Cygwin

Atom has a great package script which allows you to actually run code right in the editor. Atom kind of stands between a full-fledged IDE like Eclipse, IntelliJ, or Visual Studio and a raw text editor like Vim, Emacs, or Notepad++. Increasingly though it is becomming an IDE – with various IDE components installable as different packages. In fact I think Atom might eventually come to surpass other full-fledged IDE’s as it progresses.

I first kind of hesitated before installing the script package because it seemed like it was making things too complex and getting away from the basic text-editing functionality of Atom. But now I really love the ability to run a script in Atom. If you are writing a script and need to test it it’s very convenient to be able to immediately run it as you’re working on it.

Atom not only runs more conventional scripts like BASH or Python, it can also run Java and other languages.

If you write scripts in BASH or Python and use Cygwin to provide the BASH and Python binaries then in order for the interpreter specified on the shebang line (the top line of a script that specifies what language interpreter to run for the script) then you need to first launch Atom from a Cygwin command line.

For example here’s a basic Python Hello World!:

#!/usr/bin/python3
print(“Hello world”)

If Atom has been started from a Windows shortcut (how it is “normally” started) then it won’t recognize /usr/bin/python3 as being a valid path to the Cygwin Python 3 interpreter. The easiest way to run Atom from a command-line in Cygwin is to create an alias for it. This goes in ~/.bashrc (or ~/.bash_aliases if you use it):
alias atom=’/cygdrive/c/Users/<user>/AppData/Local/atom/atom.exe &’

Substitute in the above command with your Windows username.

Now if you have the script package installed in Atom you can run your script with Shift-Ctrl-B.