We all remember from the Tao of Programming when the master programmer avoided an embarrassing question about the presence of Tao in DOS. The good news is there is definitely Tao in Windows (but not too much).
It’s called “start“.
It’s not the Start Menu, but a command-line keyword, obviously. I’ve come to appreciate its beauty only after having spent some weeks with Ubuntu. I kept looking for something similar on the internet, and all I found was the “gnome-open” command. Still, the blog-post has ecstatic comments.
I tried “gnome-open”. It opened any file or URL with the associated program as an independent process. So far so good. Until I tried to start a program with “gnome-open”. No way. This was the moment I discovered Tao in Windows’ “start”. Let’s see:
“start” without arguments will open a new terminal window.
“start” with a CLI program as an argument will open it in a new fully independent terminal window.
“start” with a Windows program as an argument will open just that in a fully independent window.
“start” with a file or URL as an argument will open it with the preferred application.
“gnome-open” can do the latter, but not the first three options. So I decided to write my Linux-version of “start” called “go”. Please go to the page.
Back to Windows. The famous “start” has a significant drawback. As in Windows nearly none of the applications are on the PATH, start’s capabilities are just a tiny bit limited. Not so with “go”.
Another not-so-trivial problem with a beautifully simple solution within half an hour. First I created a panel launcher and started hacking its Command Line.
sudo gnome-terminal
Wrong. Nothing happens.
gnome-terminal -e su
Looks better, a terminal-window appears, but disappears again after entering the password. Should have remembered. If a command is specified, bash does not become interactive, closes when the command is completed.
sudo bash
That’s it, baby!
I still have a few problems I can’t solve. One is The Ubuntu-Firefox Font-Size Disaster. The whole internet is full of it, but no one seems to know the solution.
The problem is that on many web-pages the fonts are incredibly small. The funny thing is that Firefox on Windows displays theses pages perfectly. There are dodgy workarounds like overriding the web-page’s font settings or zoom in (and out, and in), but I can say only two words: Come On!
The other problem is the spacing and icon-size of the Ubuntu Main Menu. This monstrously huge and wasteful spacing even remains when I disable the menu icons altogether. Again, I found a lot of websites about themes and metacities and gtk, but I still have to figure out what these mysterious things mean. At least it all seems to be text-based, so I’ll find the solution one day…
It’s way too small. 80 x 25 in 2009? Utterly ridiculous.
But, as I heard before, everything can be solved in Linux, it just takes half an hour. I ended up at Maligree’s Weblog, who offers not one but 3 solutions to the problem, one for bash gurus, one for config wizards and another one for a mysterious Mister Rightclickalot.
I did all three and I’m a happy man.
I wanted to compile ogc for Linux first thing in the morning. Went surprisingly smoothly with a few tricks:
- the target is called ogc, not ogc.exe
- I had to remove the \r characters from each end-of-line of the usage and version text file sources
- Installation to /usr/bin works only with the magic sudo command.
Later I added install, uninstall and clean rules, and prepared the makefile to run on both Linux and cygwin, detecting Windows from the presence of the SYSTEMROOT variable.
Finally I put it under revision control with git. But that’s another story.
It’s no use to babble about reading books and writing Windows programs.
I still have not seen a real Unix.
After having taken some advice from an Ubuntu-fan in the office, I set out to download and write the Ubuntu-CD and install it. It was 8 o’clock in the evening.
First shot: run Ubuntu from the live CD. Not that scary. And looks bloody good, actually.
Second shot: the installation. The most heart stopping moment is when you’ve tried to set it up to shrink your Windows partition and install Ubuntu alongside with a boot-menu, and you click OK. In the next 10 minutes you just keep your fingers crossed while Ubuntu is messing with all your precious data.
But it worked. After reboot I just double-checked Windows and, after a checkdisk, it ran perfectly, as much as possible for Windows.
Move on to Ubuntu. First impression: Gnome looks very good. Second impression: it’s extremely wasteful with my screen with the default settings. Third impression: the immediate-effect settings of Gnome are a Very Good Idea.
I went to bed at 2 in the morning with much smaller fonts, just one panel at the top with a few panel launchers (terminal, mc, firefox), a single-icon main-menu and the weather shown.
So my yacc studies led me to a series of thoughts about writing my own command-line calculator with integer arithmetics. Which the Windows Calculator is not.
I set the following goals:
- 32-bit integer arithmetics (don’t ask me why, I just need it at work, OK?)
- decimal, octal and hexadecimal formats
- unlimited undo
- a fair amount of memory registers
- ability to continue from the last result (+5 should add 5 to the last result)
- no mouse clicking
- following Unix/GNU conventions
The program’s called ogc. I wrote it in yacc surprisingly quickly. The related info and the sources are available on my dedicated ogc page.
While reading esr’s book about UNIX and laziness, I found it referring to a mysterious “yacc” on many occasions. As if sed, awk, tr, ls, sudo et al were not confusing enough. I just could not resist and googled it. Voilá.
It turned out it was a high-level programming language to describe the grammar of, erm, a language, and parse it. It was created by Stephen C. Johnson back in 1973! The paper contains an appendix with an example of a simple command-line calculator.
Just try to imagine the horrors of parsing and executing simple mathematical expressions with a program written in the C language. For instance “-3*(5/2)-(5*-8)+1″.
Operator precedence, brackets, telling unary minus (-3) from the normal minus (6-2). I’d never try it.
But in yacc, the essence of the problem is solved in a few lines:
expr : '(' expr ')'
{ $$ = $2; }
| expr '+' expr
{ $$ = $1 + $3; }
| expr '-' expr
{ $$ = $1 - $3; }
| expr '*' expr
{ $$ = $1 * $3; }
| expr '/' expr
{ $$ = $1 / $3; }
| '-' expr %prec UMINUS
{ $$ = - $2; }
| number
;
This led me to a whole series of thoughts. But more of that next time…
Anyway, if yacc is yet another compiler-compiler, which was the previous compiler compiler?
It’s not what I do.
It’s the title of a book.
I found it on the internet during my initial sed adventures. The author is Eric Steven Raymond. It’s absolutely brilliant. I have been working with embedded automotive software for ages. And although I’ve never had much to do with Unix, this book pretty much sums up everything I’ve come to believe in:
Keep it simple, stupid!
Do one thing well.
Separate policy from mechanism.
Write programs to write programs.
Text rulez.
Working programs before specs and optimisation.
Fold knowledge into data, use stupid algorithms.
Design for the future.
Distrust all claims for the One True Way.
Constructive laziness is the cardinal virtue of the master programmer.
Read more…