Bash, Awk on Windows: Git-Bash and ConEmu

Every developer who has worked for some time on Linux or another Un*x system will miss the bash, some of the other unix tools like find, cat, grep and awk and a decent console bitterly.

There are several ways how to get some of the unix power back to windows.

  • Cygwin. It is sometimes a bit complicated to install and handle and there are often problems with line endings. I have used this but never was really totally content.
  • MinGW, MSYS and MSYS2. I have never used them and cannot tell much about them.
  • Git-Bash and ConEmu. Lately I have detetcted these tools and it seems they are working quite well. In this post, I’ll go a bit deeper on them. Git-Bash is a version of mingw32, as far as I know.

Git Bash

Git is a well known source control system. And its installation kit for windows contains bash, awk, grep, find and several other unix tools. So even if you don’t want to use git on your windows machine, you can install this package. It is free software.

Installation (with Git 1.9.5 from 2015/03/19) goes like this:

  1. Download the git package for windows.
  2. Run the installer.
    • Install it to tools/Git. Next.
    • Leave away Windows Explorer integration. Do not associate file endings. Next.
    • Do not create a start menu folder. Next.
    • Use Git from Git Bash only. (Other options didn’t work as intended anyway.)
    • Next. Check out Windows-style, commit Unix-style line endings.
    • Next. Wait. Finish.
  3. Create a home directory for your unix tools where you like it. Create an environment variable called HOME pointing to this directory.
  4. Add to your PATH environment variable the directory C:/tools/Git/bin.
  5. Into the directory pointed to by HOME, put a .bashrc with some aliases.
  6. Make sure that your .bashrc contains this line:
    PATH=/bin:$PATH
    This makes sure that the bash tools find and sort are in the PATH before the windows tools with the same names.
  7. Set the Double Commander terminal command to C:/tools/Git/bin/bash.exe.
  8. Done and works. Now you’ve got a usable bash with pipes and filters, awk, find, grep etc available.

ConEmu

ConEmu is a very fine terminal emulator. Download the ConEmu portable package. It’s got dozens of settings and it can be used for any consoles on windows, not only the bash. E.g. it can be used with the ordinary cmd, too.

Here is how to install it:

  1. Download the portable version of ConEmu.
  2. Extract it beneath the Git directory, to C:/tools/ConEmu.
  3. Run ConEmu.exe or ConEmu64.exe, depending on your system. Delete the other one.
  4. Select as settings location C:/tools/ConEmu/ConEmu.xml
  5. As startup task select {Bash::Git bash}.
  6. Done. Now you’ve got a nice looking console window with your git-bash inside. And for the occasional case you still need a cmd console, you can start this also inside ConEmu.
  7. And the best, you have all these things in the console you’ve missed your whole life:
    • You can copy text to the clipboard by just marking it.
    • You can insert text by typing Ctrl-v. Yes, really. No need to Alt-Space-Edit-Paste.
    • You can resize even the width of the window by dragging at the corner. Shocking.
    • ConEmu remembers its position and size and reopens at the previous place
    • There are dozens of other settings and possibilities for configuration with which you can play if you’d like to.
  8. Set the Double Commander terminal command to:
    C:/tools/ConEmu64.exe -here

000005

I’ve got the idea of combining ConEmu with Git on Windows from this post.

Things I like to have in my .bashrc:

PATH=/bin:$PATH

alias cd='pushd'
alias -- -='popd'

alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'

alias ls='ls -ACF'
alias ll='ls -l'

alias no='notepad++'

Zoomit

0516-160353-ZoomitAs a software developer who does UI, you’ll sometimes need to see exactly what is shown on your screen. You need to see pixels. You need to see pixels in large.

Mark Russinovich has built a tool called Zoomit.exe with which you can zoom into the screen fast.

It’s got these additional features:
* From Vista on, it does even live zoom.
* You can draw lines, straight lines, rectangles, ellipses.
* You can write text.
* The tool has been built as support for presentations, so it’s got a break function.

Though I use it only for zooming, I like it.

Rich Text Format

The Rich Text Format or RTF has been invented in 1987 by Microsoft. And still, it is a format that most word processors can understand. And it is very simple to create files containing RTF texts.

I use it often when I’m creating text automated or half-automated and this text shall be printed. For printing books or such, it is suited way better than e.g. Markdown.

CAVEAT Though most word processors understand RTF in some way, they do not all understand it in the same way. well. Probably your automatically created text is rendered slightly different by different word processors.
So if e.g. AbiWord 2.0 doesn’t show what you want, it pays to test your text with AbiWord 2.5 and/or further versions of other word processors.

UPDATE: In fact, many word processors seem to not understand RTF well. I had considerable problems finding one which can understand a non-standard page size with two columns and page numbers as footer. Below my results.
Disclaimer: The results stated below only reflect the cabilities of these word processors in reading a rtf file which has been created by a completely different software, written by myself. The results do not reflect in any way the abilities of the processors to read files written by themselves or by other word processors, nor do the results imply any opinion on their usability for other purposes.

  • AbiWord 2.8 can handle two-column layout and page size quite ok, but not together with page numbers. It can handle page numbers with some special nonstandard tags, it seems. But still ignores the \pgnstart tag.
  • AbleWord v3.0 is one of the few that can handle two columns, page size and margins correctly. Has problems with fonts, but I may be able to work around these.
  • AngelWriter 3.2 cannot handle two-column layout at all.
  • Atlantis 1.6.6.5 can handle two-column layout, fonts, page format and margins. It even understands the \linebetcol-tag. It has the unique “feature” that a page break will lead to distributing the text on the page to the two columns. Otherwise, maybe the best one for my purposes.
  • Axenicsoft Nifty Author 1.3 is another one that can handle two columns, page size and margins. It even is able to use the fonts orderly. Like Atlantis it interprets \sect\page as two page braks. And it needs some very special non-standard-tags for the footers and does startup quite slowly. No way to switch off the spell checker. But then, all in all, it seems to be ok.
  • Bad Wolf SmartEdit 3.421 cannot handle two column layout at all.
  • Corel Office 16.0 wants to have you register yourself, even for the 30 day trial version.
  • DevVicky Word 2010: According to VirusTotal, the packet I downloaded may be malware infected.
  • Kingsoft Office Suite Free 2013 Writer: Cannot handle page size and margins. And cannot handle well multiple fonts in one document.
  • LibreOffice 4.0 does not handle two-column layout well.
  • Nevron Writer 2.0: Hangs when trying to view print layout.
  • OpenOffice 3.4 does not handle two-column layout well.
  • PolyEdit 5.4 cannot handle two-column layout at all.
  • PolyEdit 6 beta is only available to registered users.
  • QJot 5.9.1 The packet I got from the web is probably malware, according to VirusTotal.
  • SSuite Office QT Writer Express 2.8.1.1 cannot handle fonts nor two columns.
  • Verbum 2012: Does not handle margins correctly. Otherwise not bad, very similar rendering to Nifty Author, but starts up faster. Printing possibility lacks.
  • WordIt 0.1 Alpha 1: does not understand rtf at all.

This is a good desription of Richt Text Format/RTF specifics.

Delayed Hibernation Or Shutdown of Your PC

timeout /t 600 & shutdown /h

waits for 600 seconds and then puts the computer into hibernation.

Sometimes, it is desirable to be able to shut down your PC at a later time. For this task, there is the command line command shutdown on MS Windows PCs. Shutdown has a lot of options and I don’t need most of them most of the time. You can see them by running shutdown /?.

What I want is mostly to put the PC into hibernation in some time from now on. According to shutdown /?, shutdown /h /t 600 should do the trick and put the computer into hibernation in 600 seconds from now. But it doesn’t. I don’t know why, but the switches /h and /t do not work together with the shutdown command. There are two simple workarounds. For Vista and later, you can chain a timeout and a shutdown command with the &. So,

timeout /t 600 & shutdown /h

does what I want.

But on pre-Vista PCs, there is no timeout command. There you can use 600 pings to localhost to wait 600 seconds:

ping /n 600 127.0.0.1 & shutdown /h

shutdown /s /t 600 shuts down the computer in 600 seconds from now. This one works like it should.