• Forum
  • Lounge
  • "Editor & Console" Programming on Window

 
"Editor & Console" Programming on Windows HOWTO

I've mentioned once or twice that I don't like to program with an IDE; I prefer to use the command-line, a decent WYSIWYG editor and hand-written Makefiles. I've also complained about Windows having poor graphical/textual shell integration which makes it unsuitable for this kind of programming. But it's possible to change that and I've finally gone to the effort of doing it.

You will need:
1. A decent editor. Windows only comes with Notepad, which has no highlighting, no auto-complete, no bracket matching, etc. (optional for masochists)
2. Command-line tools. The command-line tools that come with Windows just plain suck. They're sparse and awkward to use. The only one that ever impressed me was diskpart and that's not very useful for programming. (required)
3. A decent terminal emulator. The Windows shell (cmd.exe) and terminal emulator (conhost.exe) suck. cmd has dumb completion behaviour, lacks useful features and isn't customisable. conhost is barely customisable and has the worst text-select behaviour I've ever seen in any program ever. (optional)
4. Graphical/textual shell integration. AFAIK all popular Linux file managers have a context-menu option such as "Open Terminal Here", or it is easy to get one. Windows doesn't but it's surprisingly easy to add. (optional


A Decent Editor
Hands-down the best editor for Windows programmers is Sublime Text. Get it from http://www.sublimetext.com

It has a great interface, it's very customisable, it has syntax highlighting for most programming languages. For those it's missing, like shader and assembly languages, you can usually find a package on Google. Here are a couple:
* ARM assembly: https://sublime.wbond.net/packages/ARM%20Assembly
* shader languages: https://bitbucket.org/asmodai/shaderlanguages
* x86 assembly (NASM syntax): https://sublime.wbond.net/packages/NASM%20x86%20Assembly

However, if you can't or won't pay for it, don't want to use the trial version (which, I assume, bugs you about upgrading to the full version and is probably partly broken) and are piracy-averse or want to use free software, Notepad++ is probably the next best thing.

Command-line Tools
Windows comes with a "POSIX subsystem" which, I assume, includes many command-line tools, but I imagine they're probably quite half-assed like the BSD tools. The GNU people may not know how to write legible code but when it comes to feature-completeness, they're unrivalled. Also, I very much doubt the POSIX subsystem includes compilers or anything of the sort, so it's probably a waste of time. If you want to try it out, you need to find Turn Windows Features On or Off in the control panel (on Windows 7, open Control Panel, click Programs and find it under "Programs and Features"). It will probably take a while and be a waste of your time.

Your next option is MinGW (Minimalist GNU for Windows). As the name suggests, it's quite minimalistic: it contains everything you need to build software targeting Windows (binutils and GCC) but not much else. It also does not provide a POSIX runtime. If that's enough for you, get it from http://www.mingw.org/

The third option, and my personal preference, is Cygwin (a pun on the constellation Cygnus (sig-nus) and Windows). It consists of two parts: a runtime library implementing much of the POSIX specification (enough to build most POSIX-compliant software with little or no modification) and a package manager for installing and updating a fairly large volume of ported software, including Boost, Python, Perl, the entire GNU catalogue (or at least most of it), clang/llvm and even an X server that, combined with an SSH client like PuTTY, can display X applications running on a different computer. Because of the package manager, it's entirely possible to have an installation no bigger than that of MinGW, but if you want, you can have a full POSIX environment. Get it from http://www.cygwin.com/

There may be more ways to get POSIX-like command-line tools on Windows, or even a different toolset entirely, but I'm not aware of any. I do believe the Plan 9 userland tools have been ported; they may be worth taking a look at.

A Decent Terminal Emulator
At the moment, I am using ConEmu. It's feature-rich and reasonably customisable. I have also used Console2 and MinTTY. None of them are as good as gnome-terminal (the GNOME 2 version - the one that ships with GNOME 3 is "stripped down" [read: broken]) but that's not available for Windows.

* ConEmu: https://code.google.com/p/conemu-maximus5/
* Console2: http://sourceforge.net/projects/console/
* MinTTY: https://code.google.com/p/mintty/ (or via Cygwin package manager)

None of these are really worth using with cmd.exe, so make sure you get a decent shell like bash or zsh in step 2 (another reason to use Cygwin over MinGW or "POSIX subsystem").

Shell Integration
The final thing to do is to integrate your new terminal emulator with the Windows shell. For this, we will need to make some changes in the Windows registry. Open regedit.exe and navigate to HKEY_CLASSES_ROOT\Directory\Background\shell. Right-click "shell" and click New>Key. The name of the key is the string that appears on the Windows Explorer context menu. I used "Open Terminal Here". Then create a new key under that called "command", double-click the value "(Default)" and set it to the path of the program you want to run. You must escape the backwards-slahes ("C:\\" not "C:\") or it won't work. I used the string 'C:\\Programs\\System\\ConEmu\\ConEmu64.exe /cmd "bash.exe"' which opens ConEmu (64-bit) with bash as the shell. Now go into Windows Explorer and right-click the background of the pane (i.e. not on a file or directory) and you should see "Open Terminal Here". When clicked, it should open the program with the current directory in Explorer as the program's current directory. This way, you will not have to cd to your project directory every time you open the terminal.

If you want the Open Terminal Here option to exist for the directory context menu (i.e. when you right-click on a directory) as well as (or instead of) when you right-click on the pane itself, create the new keys in HKEY_CLASSES_ROOT\Directory\shell instead of (or as well as) Directory\Background\shell. However, this time you will need to tell Explorer to pass the path of the directory you right-clicked to the program because otherwise it will use your current directory. With ConEmu the command-line switch is "/dir" and the path is "%1", so for my system the full string is 'C:\\Programs\\System\\ConEmu\\ConEmu64.exe /dir "%1" /cmd "bash.exe"'. Note that, with ConEmu, the /cmd switch and its value must go at the end of the line, because it interprets everything after that as arguments to the program, and bash doesn't understand the "/dir" switch. You will also most likely want to put quotes around %1 -- otherwise, if the directory name contains a space, everything after the space will be considered a separate parameter.

Also useful:
If, like me, you like to use extensionless README, Doxygen and Makefiles, it's probably a bit annoying to have to select your text editor each time. To fix this, open the Windows shell (cmd.exe) and type

1
2
assoc .=txtfile
ftype txtfile="<path to editor>" %1

Alternatively, you can just give your files extensions.
Last edited on
I haven't broken out the fine tooth comb yet but at first glance this appears to be concise and informative. Are you prototyping for an article?
Topic archived. No new replies allowed.