Bash Job Control

September 24th, 2009 subogero Comments off

Having already explored the  possibilities of starting parallel processes using the Gnome window-manager, as described on my go page, it was high time to immerse myself, being the keyboard-addicted geek that I am, into doing the same by using just a simple terminal.

But what’s the point? In my case, it was a commit process with a revision-control system called foo. The commit is done with a script, and I wanted to make sure the project compiles OK before the actual commit.

This involves two quite long processes, which could nicely run parallel, one is composing the commit-message with an editor, and the other is the compilation. We shall go on with the commit after BOTH are finished. Oh, I nearly forgot, the commit shall be canceled, if the compilation fails!

I studied bash job-control a bit and then:

# The '&' character runs the command in the background
# which in turn becomes job number 1, later referred to as %1.
make &

# Compose the commit-message in the foreground
foo-status > CommitMessage
mcedit CommitMessage

# Wait for the make (job 1, alias %1) to complete,
# check its exit status and abort if it's failed.
# The 'wait' command's exit status is the same as the job's we wait for
wait %1
if [ $? -ne 0 ]; then exit 1; fi

# Do the commit
foo-commit --message=CommitMessage
rm CommitMessage

Try this with batch-files on Windows. Actually, you can do it with Cygwin. I’m sure Richard Stallman calls this platform GNU/Windows.

Bash is cool. Bourne Again Shell for Born Again Christians, that’s what I always say. Or as Master Foo put it once:

“There is more Unix-nature in one line of shell script than there is in ten thousand lines of C.”

Categories: Uncategorized Tags: ,

Compile on Linux for Win32

September 12th, 2009 subogero Comments off

This is perverse. I’ve just compiled a native Win32 application on Linux. What’s even more perverse it runs on Linux too with Wine.

To cut a long story short I needed a command line tool to send emails using the MAPI protocol, the only language spoken by Outlook and MS Exchange. Don’t ask me why. It’s by the way my first ever Win32 application using the Win32 API. Or `mapi.h’, to be precise.

I started developing it on a Win32-cygwin platform with gcc, but I wanted to control the sources with git. Which prefers Linux. So I ended up rebooting the box a few times to change between the two. But I’m extremely lazy, so I soon googled for a way to cross-compile Win32 programs on a Linux host. It did not take long. I summarize my findings in a few lines:

What to install:

sudo apt-get install mingw32

How to compile:

i586-mingw32msvc-gcc -L/usr/i586-mingw32msvc/lib \
  -I/usr/i586-mingw32msvc/include -o foo.exe foo.c

The result? See the mapis page.

Categories: Uncategorized Tags: , , ,

Midnight Commander and Cursor Beyond End of Line

September 7th, 2009 subogero 2 comments

Two weeks ago I had a short glance at the Midnight Commander’s Roadmap and found that 4.7.0-pre2 was to be relased end of August. Looking through the tickets what do I see? Cursor beyond end of line in the built-in editor.

I’ve just arrived from the world of those glassed openings on walls, which should illuminate the inside of buildings during the working hours. In this world, I was obviously the victim of evil (and rude) monopolies, that should not be named in polite company. But even these despotic dictatorships have advantages. The oppressed subordinates may enjoy the cursor going beyond the end of line in all text-editors that are worth mentioning (step forward, Far-manager).

Having arrived in the free world, I received one nasty shock after another every time I wanted to go up two lines to the same position in text-editors. If the line in between was shorter or empty, the cursor endeavoured to jump back and stay there. Just like… erm… I have to say it, Notepad.

Gedit is like that. Emacs is like that. Midnight Commander’s editor is like that. Or has been, until now.

Having returned from a week long cycling trip from the Italian Alps, my life has become completely meaningless, at least in the eye of the Master Programmer, as in the absence of computers I had to abstain from programming for more than the official limit of 3 days. To restore my form, the first thing was to download mc-4.7.0-pre2.

Binaries are not provided, only sources, so I had to configure the makefile and compile it. The configure script disliked my Ubuntu-installation in a marked manner. It raised its eyebrows, pursed its lips and refused to produce any usable makefile. Some obscure gmodule-2.0 was missing. But after a considerable amount of googling, synaptic-package-managing and trying I had a running MC with the editor allowing the cursor to go beyond the end of line.

For the benefit of the general public I now kindly publish the major milestones that helped me achieve this majestic goal:

sudo apt-get install build-essential
sudo apt-get install libglib2.0-dev
sudo apt-get install libslang2-dev
sudo apt-get install gettext
sudo apt-get install libtool
./autogen.sh
./configure --with-samba
make
sudo make install

Bulk Rename – Replace Space with Underscore

August 26th, 2009 subogero Comments off

A small script to perform bulk renaming of files, replacing spaces with underscores and exotic letters with sanitized versions.

Save this link as /usr/bin/s2u.

#!/bin/sh
ls -1 | while read -r FILE; do
  mv -v "$FILE" `echo $FILE | tr ' áéíóöïúü' '_aeiooouu'`;
done
Categories: posts Tags: , , ,

Firefox Hotkeys

August 16th, 2009 subogero Comments off

I always found Tab-based programs like Firefox awkward to use, as I could not change between or close tabs with the known Alt-Tab, Alt-F4 hotkeys. Until now.

Check out this extremely useful post.

New tab             Ctrl-T
Close tab           Ctrl-W
Undo close tab      Ctrl-Shift-T
Next tab            Ctrl-Tab
Last tab            Ctrl-Shift-Tab
Bookmark tab        Ctrl-D
Select address bar  Alt-D
Select search bar   Ctrl-K

Never have to ckick again in Firefox !!! Erm, on second thoughts…

Categories: posts Tags: , ,

Ubuntu vs XP Reboot Time

August 15th, 2009 subogero Comments off

I’ve just measured full reboot times with Ubuntu and Windows XP on the same machine.
Bonus: reboot times with Ubuntu Jaunty on Asus UL20A laptop (its BIOS is extremely fast too).

                             Ubuntu       XP  |  Ubuntu ASUS UL20A
----------------------------------------------|-------------------
boot from BIOS until login     26 s     29 s  |                17s
boot from login until ready    16 s     39 s  |                15s
reboot until BIOS              19 s     35 s  |                12s
----------------------------------------------|-------------------
overall reboot without BIOS    63 s    103 s  |                44s

No comment.

Categories: posts Tags: , ,

Manual Pages

August 15th, 2009 subogero Comments off

The day has come, and I’ve started writing documentation, but this time Linux style. In other words, I’ve just created the manual pages for my Newbie-projects, “ogc” and “go“.

Some important points I’ve learned from the Linux Man Page Howto:

Manual pages are written in the “groff” (GNU troff) markup language. Just start from another program’s man page, it’ll be easy.

Manual pages of user-commands shall be installed into “/usr/share/man/man1″

The manual page of user-program “foo” shall be called either “foo.1″ or “foo.1.gz” (gzipped).

To read foo’s manual page, type

man foo

It’s that easy.

Categories: posts Tags: , ,

Automount an NTFS Partition

August 14th, 2009 subogero 4 comments

As I have a Windows-Ubuntu side-by-side installation with a boot menu, I still store a lot of data on the NTFS partition. I know, I know…

Ubuntu endeavours to give satisfaction, so you can see all detected storage devices in the “Main Menu” under “Places”. Click your NTFS partition, and it’s mounted automatically to /media/disk/.

But if you want to access these files from another program before clicking it in “Places”, it does not work. So I googled “automount ntfs partition” and there it was.

I added the following line to “/etc/fstab”:

# <file system> <mount point>   <type>  <options>                <dump>  <pass>
/dev/sda1       /media/disk     ntfs    users,defaults,umask=000 0       0

I rebooted. I did not work. It took me a few days until I realised one cannot mount something in a non-existent directory. When you click your NTFS partition in “Places”, Ubuntu not only mounts it, but creates the mount-point directory “/media/disk” first. But just adding something to “/etc/fstab” does not create directories. People would talk. Eyebrows would be raised.

After a

sudo mkdir /media/disk

and a reboot it worked perfectly.

This must be ridiculously obvious to a Hacker, but the post may help a Newbie or two like myself.

Categories: posts Tags: , ,

Perfection in Design

August 11th, 2009 subogero Comments off

From esr’s book “The Cathedral and the Bazaar“:

Antoine de Saint-Exupéry (who was an aviator and aircraft designer when he wasn’t authoring classic children’s books) said:

Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Categories: posts Tags: , ,

Gnome Main Menu Icon Size – Solved

August 10th, 2009 subogero Comments off

The problem with the Main Menu’s huge icons and spacing is solved. I’ve just found the tool called GNOME Color Chooser. Go to the “Icon” Tab.

sudo apt-get install gnome-color-chooser
Categories: posts Tags: ,