Mutt aka Bash Is Still King

December 5th, 2011 subogero 4 comments

I’ve had problems with sending emails from the command line before. On Windows. That’s how mapis was born. This time it’s the same story on Linux. I want to send an email from the command line with an attachment. The rather lovely Evolution does not support it.

In comes mutt, the even more lovely terminal based email client. But I don’t want to loose features:

  • Gmail IMAP access
  • integration with my Gmail contacts
  • Hungarian spell-check
  • mutt as my default mail client in Gnome, so Firefox uses it when Sending Link…

And while I’m at it, I want some new features as well:

  • editing email with vim (with Hungarian spell-check, obviously)
  • bonus: email desktop notifications, even when the client is not running

Installation

apt-get install mutt  # as root

My ~/.muttrc config file:

set from = "your@email"
set realname = "Your Name"
set imap_user = "your@email"
set imap_pass = "yourpassword"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed = "+[Gmail],Drafts"
set trash = "imaps://imap.gmail.com/[Gmail]/Trash"
set header_cache = ~/.mutt/cache/headers
set message_cachedir = ~/.mutt/cache/bodies
set certificate_file = ~/.mutt/certificates
set smtp_url = "smtp://your@email:587/"
set smtp_pass = "your_password"
set editor  = "vi"
set query_command = "goobook query '%s'"
set sort = "threads"
set sort_aux = "last-date-received"

color normal white default
color index white default ~p
color index white default ~P
color index white default ~O
color index brightwhite default ~N
color tree red default
color hdrdefault cyan default
color quoted green default
color tilde white default
color signature blue default
color attachment brightyellow default
color status brightwhite green
color indicator black white

You’ve probably noticed vi as the editor, some options that don’t let you miss new posts to old email threads and a colour scheme that fits well into Linux Mint. Also goobook is mentioned, which can access your Gmail  contacts from the command line. Homework: find the goobook website on the internet! Then download and extract the source tarball, run

sudo ./setup.py install

Then create its config file ~/.goobookrc

[DEFAULT]
email: your@email
password: your_password

As the above config files store your password, don’t forget to change their permissions:

chmod 700 ~/.muttrc ~/.goobookrc

As to the Hungarian spell-check in vi, add a line to ~/.vimrc which maps it to <F7>, like some office tools:

map <F7> :setlocal spell spelllang=hu<Enter>

The first time you activate it, it will download the Hungarian database, then highlight the misspelled words with red. Move around them with [s and ]s and let vim suggest correct spelling with the z= key combo. It kicks ass indeed.

Mutt as Gnome’s default email client? Main Menu (I don’t use the Mint Menu), System, Preferences, Preferred Applications. Mail Reader. Choose Custom, then specify “/usr/bin/mutt %s” as the command. Run in terminal of course. Test with Send Link… in Firefox.

Now all is well. Just try to send a file attachment from the command line.

mutt -a foo.txt

opens mutt, which in turn asks for the mail recipient. Just type a part of the name or email, hit Ctrl-t, and mutt will complete the email address from your Gmail Contacts. Then enter a subject and voilá, vi opens up to edit the mail body. Edit, spellcheck, ZZ, y. Done.

And now for something completely different. Desktop notifications for new email, even when no email client is running. I’ve found a nice mutt-Gmail tutorial blogpost somewhere, I forget where. It contained a Python script for email notifications. I opened it. I got scared. 200 lines of code! I nearly gave up. But after  taking a courageous look I realized it just parsed the Gmail atom feed and called Gnome’s notify-send. Using a class and using an XML parsing module.

Python is a rather lovely language, but I have to say its adherents are famous for writing bloated code. I bet I can write a 10-line shell script for that. I ended up with 11 lines, but including the shebang and a configurable checking period. It’s among my Gnome Startup Applications:

#!/bin/sh
SLEEP=`echo $1 | egrep '^[1-9][0-9]*$'`
[ -z "$SLEEP" ] && SLEEP=300
USER=`sed -rn 's/^set imap_user = "(.+)"$/\1/p' ~/.muttrc`
PASS=`sed -rn 's/^set imap_pass = "(.+)"$/\1/p' ~/.muttrc`
while true; do
 EMAILS=`curl -u ${USER}:${PASS} https://mail.google.com/mail/feed/atom \
 | sed -rn 's/<name>(.+)<\/name>$/\1/p'`
 [ -n "$EMAILS" ] && notify-send "NEW EMAIL" "$EMAILS"
 sleep $SLEEP
done

Bash is still king.

Categories: Uncategorized Tags: , , , ,

Gnome3

November 29th, 2011 subogero No comments

I gave it a go, after I read a positive blog-post about it. So I installed Fedora16 as a new VirtualBox machine. Then I installed VirtualBox guest-additions to enable 3D-acceleration, without which one is confronted with the 2D fallback mode, which shall not be mentioned in civilised company.

Finally I was presented with the new shiny uncluttered Gnome Shell. I hit Alt-F1 to see the menu. There emerged the even more shiny semi-transparent Activities page. Surprisingly, it was rather empty. I wanted to start something like a browser or a terminal with the keyboard. So I hit the arrow keys, Tabs and stuff to get to “Applications” instead of “Windows”, or to the hierarchical menu on the right side. Nothing. In about 5 minutes – googling included – I have not found any key combination the Activities page recognizes. There is probably something like Ctrl-Alt-Shift-arrow, which needs 3 hands to operate.

So, rather sadly, I resorted to using the mouse and started a terminal. I was immediately presented with an unpleasant huge silver title bar. So much for uncluttered. So, yes, let’s customize the desktop theme. Right-click the desktop. Nothing. Hmmm. Alt-F1 for Activities, somehow I found Settings. It turned out all you can do is change the background image. Hmmm, indeed. Compiz will probably sort it out.

Or rather not. Compiz is not available. Good bye Rotating Desktop Cube, good bye Ring Switcher, good bye semitransparent Wobbly Windows. One might say I’m an effect-junkie, but the fact is these Compiz bells and whistles actually help you see what you do. On the Cube, you see what is on the next desktop. With a semitransparent moving window, you see where you place it. With the Ring Switcher after Alt-Tab, you see what window you choose. Which is not the case with Gnome3’s Alt-Tab, which displays icons only. Welcome back to the wonderful world of Windows XP.

Having mentioned terminals, I wanted to open a second one. Activities, click Terminal, and Gnome3, endeavouring to give satisfaction, returned me to my old Gnome-terminal. Thank you very much.

So back to customization. You cannot choose your fonts. You cannot choose your colours. You cannot choose your keyboard shortcuts. You probably can, but you need extensions and special config tools and config file editing. Need an extension to choose my fonts? Weird. The Windows XP registry springs to the mind. Not funny.

But c’est la vie, I yummed gnome-tweak-tool. Suddenly a whole new world of options opened up, like choosing fonts. Not colours, though. I’d say about 10% of the options of Gnome2-Compiz. At least I could select my favourite MetaBox window borders. Or rather the Metabox non-borders.

The issue of window borders brings me back to my favourite obsession, vertical space. Or in the case of Gnome3, the lack of it. You must have a panel, and you must have it on top. You must have a window title bar and you must a have a menu. In Unity, for a maximized window, the panel, the title bar and the menu are one. In Gnome2, you can place the panel to any side and make it auto-hide.

And sorry, but I have not seen any nice effect that necessitates 3D acceleration. Gnome3 does not look too good. It’s a desktop, which is a piece of furniture, which, by definition, must look good. Mac OS X looks good. Unity looks good. And Gnome2-Compiz simply blows everything else away.

Gnome2-Compiz was actually so bloody good that Apple copied many features from it. I still remember the day I first installed Jaunty Jackalope after living for years in a desert called Windows XP. I was amazed by the myriad of desktop customization options: Configurable window decoration! Configurable controls! Configurable panels and applets! Configurable hotkeys for everything! Semi-transparent terminals! A sane algorithm for placing new windows! Not even mentioning the rather mind-blowing Compiz stuff. And suddenly, Windows XP looks like an oasis of freedom compared to Gnome3.

What’s going on here? I’m probably very stupid. Too stupid use Gnome3. At least I’m in good company. Linus Torvalds can’t use it, either.

The Command Line Is Outdated

November 23rd, 2011 subogero No comments

The command line has been outdated for 20 years.

This is the claim I heard yesterday from a colleague, along with a statement that he needs useable interfaces. The revelation came during a discussion about git vs MKS Source Integrity*.

Why, one might ask, comes Windows 8 Server, for the first time in history, without a GUI?  Why do retarded Linux freaks still claim that the command line is way more effective than any GUI?

The shocking answer is that, surprisingly, the command line is our natural way of communication since the dawn of the human race. We have an organ to form and send text streams. It’s called the mouth. We have another pair of organs that receive text streams. The ears, ladies and gentlemen. We also have a way of batch-processing these messages. Some would call it reading and writing. Others call it literacy.

That’s the reason that, against all odds, the only remaining paradigm of the last half century of computing is Unix, which embraced TEXT as its core value. Everything is a file, in other words a stream of characters, text.

What is the very essence of the C language, the ultimate superclass of all superclasses, which is compatible with everything by definition? It’s this, the pointer to the universal byte stream:

void *

And we’ve just arrived to the most crucial question. Why do so many people still despise the command line? Exactly. Because it involves learning languages.

But come on! By the age of two, everybody has learned one. It’s not that difficult. Of course, we all start with GUIs. We click our toys. We play with the mother of all GUIs, our Mom’s b… erm… buttons.

But as time passes, our parents watch with ecstatic joy as we form our first text streams. They tell their friends about it. Then we go to school and what do we learn first? Scripting.

I’ll go further. The command line is older than the human race. Text is more universal than the universe.

In the beginning was the Word, and the Word was with God, and the Word was God.

Chew on that, you serial clickers.

* Some would propose a better name: MKS Source Disintegration.

Categories: Uncategorized Tags: , , , ,

CyanogenMod 7 Update

November 11th, 2011 subogero No comments

A few days after installation, I wanted to install ssh onto the phone. I turned out dropbear is installed by default, I just had to set up some keys.

Then, to my utter amazement, I found a bash directory in /etc. I typed bash, and suddenly there it was, the world’s favourite shell in all its glory and coloured prompt!

CyanogenMod 7 on MotoDefy

November 7th, 2011 subogero No comments

I’m happy to report that the Bluetooth issue with the helmet headset was due to a broken mic wiring. No battery problems either.

And now back to the actual installation of CM7 to Moto Defy. This description is based on two excellent and detailed articles in Hungarian on androidunderground.info:

And now let’s get down to business.

Precautions

Your phone could be bricked during the process. No warranties, blah blah blah.
Use the download links here. The internet is full of crap.
Fully charge the phone’s battery and use a laptop to avoid problems due to power failures.
I used the company laptop with Windows XP, because the rooting program is for Windows.
Back up your data. I did not, as contacts are synced with Google and all else is on the SDcard.

Backups are for whimps (Linus Torvalds)

1. Install official stock Froyo

Only if you have an older device which came with Android 2.1.

You need the Motorola drivers for the PC. Download if the USB connection does not work.

Motorola has released an official update program for Windows. Download. Search the net for other details.

2. Root Your Phone

Download the SuperOneClick program for your PC. There are many versions, and most don’t work with this phone. Use this link.

Allow USB debugging on the phone: Settings / Applications / Development / USB debugging

Connect phone to PC via USB. Pull down phone statusbar, tap USB Connection, select ‘Charge Only’ or ‘Motorola Phone Portal’.

On PC, start the SuperOneClick program (as admin on Win7). Click the ‘Root’ button. Wait 1-2 minutes until the ‘Device is rooted’ dialog pops up, click OK, close SuperOneClick.

Restart phone. Check whether rooting was successful by starting Terminal Emulator on the phone and typing ’su’. The Superuser app should pop up asking for permission.

3. Install 2ndInit ClockWork Custom Recovery

Allow unknown app sources on the phone: Settings / Applications / Unknown Sources.

Install the 2ndInit program on the phone. Download, copy to phone SDcard, On phone, start File Manager app, go to SDcard, find and click SndInitDefy_1.4_2.apk program, Install, Open.

Tap ‘Install 2ndInit Recovery’ button. Tap ‘Allow’ twice in the subsequent Superuser Request popups.

Disable USB debugging on the phone: Settings / Applications / Development / USB Debugging

Reboot phone, you will get into boot menu.

  • Select ‘+Boot –>’ with volume buttons, push power button
  • Select ‘+Set Default –>’ push power button
  • Select ‘+Normal –>’ push power button
  • Select ‘–Go Back’ push power button
  • Select ‘[Reboot System]‘ push power button

After this second reboot you get back to Froyo, but the CustomRecovery is installed already. We’re ready for the actual CM7 installation.

4. Install CM7

Download the lastest stable version and GoogleApps as well. Copy them both into the root folder of the SDcard.

Restart phone, after 8 seconds from start the blue LED is switched on (indicating that 2ndInit is working). Push Volume Down while blue LED is on to get into boot menu.

  • Select ‘+Recovery –>’ push power button
  • Select ‘[Custom Recovery]‘ push power button
  • Select ‘- wipe cache partition’ push power button
  • Select ‘- Yes – wipe cache’ push power button
  • Select ‘- wipe data/factory reset’ push power button
  • Select ‘- Yes – delete all user data’ push power button
  • Select ‘- install zip from sdcard’ push power button
  • Select ‘- choose zip from sdcard’ push power button
  • Select ‘update-cm-7….zip’ push power button
  • Select ‘Yes – Install …’ push power button
  • Select ‘- choose zip from sdcard’ push power button
  • Select ‘gapps-gb….zip’ push power button
  • Select ‘Yes – Install …’ push power button
  • Select ‘+++++Go Back+++++’ push power button
  • Select ‘- reboot system now’ push power button

Your phone will now boot into CyanogenMod 7. The first boot is slow and you should go through a lot of initial settings. Have fun.

Cooking

November 1st, 2011 subogero No comments

This post is about the richness of hacker-lingo. Let’s take, for instance, custom ROMs for Android devices. The real name of the phenomenon is actually “cooked ROM”. Let just savour the beauty of this expression for a moment…

After some frustration with the slowness and general crapness of the official Motorola Froyo for my Defy, I’ve finally made up my mind and installed CyanogenMod-7 last Friday. I’ve followed the instructions of an excellent guide in Hungarian. General impressions:

I’m root by default and busybox is installed. Good start.

The amount of configuration options is mind-boggling.

The status bar is black at last. And the home screen auto-rotates as well.

It’s bloody fast.

It works.

It plays the most fluid liquid drum and bass all day long from my favourite internet radio. It plays offline music and navigates in the car. It GPS-tracks my cycling routes. It can read and write email. It can browse the web. It syncs my contacts between the phone and Evolution automatically via Google. It takes pictures. It browses pictures, much better and faster than the utterly crap Moto-Gallery. Blimey, it can even make phone calls!

It reads the Bible in Hungarian, Greek and Hebrew, just to name a few. Thanks to the new app and-bible. It’s sooooo much better than YouVersion. Swipe left for next chapter. Get to the Hebrew Aleppo codex with one tap. Local search. No pretend-to-be-social-internet-junkiness. Just do one thing extremely well. Respect.

Back to CM7, I have a week impression that it’s a bit heavier on the battery than the stock firmware. But it needs to be confirmed.

Tomorrow is the big day. We’ll test whether it connects via Bluetooth to the helmets of the great Defy-using-and-motorcycling community at the office. Which the original Moto firmware does not. Keep fingers crossed.

Gits and Bugs

October 24th, 2011 subogero 2 comments

One may wonder what was happening in the last few months. Everyone knows about the Euro-crisis. A certain Mr Erdogan has been trying to revive the Ottoman Empire, sharpening his Unix-skills, especially bashing, on Israel.  Mahmoud failed to turn Judea and Samaria into a Judenrein state at the UN. It also turned out that a single Israeli soldier is worth 1027 heroic Palestinian freedom fighters. What’s more, Muammar Kadhafi, in a markedly Perl-like fashion, said:

keep $power or die $!

Yes, but what about the real important stuff, you may ask. Oh, I see what you mean! Here it is.

I needed a recursive git-grep function to scan submodules as well. So I wrote one. Along with a vim-plugin, which is a beautiful piece of plagiarism, but that’s open source for you!

http://github.com/subogero/git-grep-recursive-vim

I got acquainted with gdb, the GNU Debugger, courtesy of Richard Stallman. Typical of him, it prints 2 pages of licensing info and political agenda when started up. But after you get rid of that,

alias gdb='gdb -q'

what a brilliant piece of software it is! Easy, comfortable, fast, debugging on the command line. It’s just incredible. Gdb is a bit better explained here:

http://betterexplained.com/articles/debugging-with-gdb/

I rewrote my calculator, because one had to type too many uppercase letters for hex numbers. It’s all lowercase now. And it’s called “szg”, and no, not after my initials. It means SZámolóGép, which is Hungarian for calculator. Nothing to do with Hungarian notation, though. Which one of my colleagues turned out to actually like. Strange taste. It must give a deep satisfaction, when after 2 years of maintenance “u8Foo” has become a signed long.

Anyway the new calculator is available on github:

http://github.com/subogero/szg

At the office, I’m now co-developing a rather large project in git with a colleague. Lots of fun…

Having mentioned Muammar Kadhafi, there was a lot of hype about the death of Steve Jobs recently. A much more important person has passed away too: Dennis Ritchie, creator of the C programming language, co-creator of Unix with Ken Thompson. As a tribute, some quotes from the two heroes:

Obviously, the person who had most influence on my career was Ken Thompson.
Dennis Ritchie
That brings me to Dennis Ritchie. Our collaboration has been a thing of beauty.
Ken Thompson 
Categories: Uncategorized Tags: , , , ,

ogc 6.0rc2

July 18th, 2011 subogero No comments

ogc 6.0 rc2 is out for the general public to enjoy. It now supports any number of user defined variables in the form of $FOO or $SPAM. Dollar sign plus all-caps. I know, it’s somewhat LarryWallesque. The dollar-sign, not the all-caps, you understand.

Just to show the severity of my mental state, I’ve implemented “hash-buckets” in C. With vi.

vi Cheat Sheet

July 4th, 2011 subogero No comments

I’ve just reached a very severe stage of the disease called Unix. I’m learning vi.

I still vividly remember the shock when a command-line Linux expected me to edit something and kindly opened up vi for me. I did not know how to exit, so I had to shut down the computer.

After using pagers (more or less) and manual pages for some time, I slowly learned a few important hotkeys like “/pattern” to search forward for something, “n” to find the next match and “q” to quit. Playing the command-line version of robots, one quickly memorizes “h”, “j”, “k” and “l” for navigation. It turns out they all come from vi. Or vice versa.

But before going on, I’d like to enlighten my readers about quitting vi:

:q<Enter>   Quit
:q!<Enter>  Quit and discard changes
:wq<Enter>  Save and quit
ZZ          Save and quit

Now that quitting is out of the way, let me tell you about a few highlights of my steepish vi learning curve. It seems the usefulness of Unix tools is proportional with their scariness.  Same as with git.

Those 1-2-letter commands are quite logical, actually, usually consisting of a command and a move, eg “dw” stands for delete word.

Let’s take moving around in the window. After scrolling down a few pages, you find the interesting line, but it’s in the bottom of the screen along with the cursor. Command “z.” will put it in the middle.

When you try to select something with a Windows-style editor, you press Shift at the beginning, keep it pressed and move around with the arrows. Then you realize the beginning is at the wrong position. You can start over.

In vi, on the other hand, you press “v” for visual selection, move around to find the end of the highlighted block. Then you notice the beginning is wrong. Press “o” for opposite, your block’s end will get fixed and the cursor jumps to the beginning, which you can now move around. Astonishing!

And now to something completely different: the vi Cheat Sheet!

vi Chet Sheet

vi Cheat Sheet

Bonus: I was always wondering what text editor I should install onto my Android phone. I’ve just realized that busybox-vi has been there all the time. It works perfectly with the crude virtual keyboard.

Bonus 2: my ~/.vimrc file with syntax highlight, line numbers, autoindent, highlight search results and, most importantly, brighter foreground colours.

syntax on
set number
set autoindent
set hlsearch
set background=dark
Categories: Uncategorized Tags: , , , ,

Mount Samba Shares on Linux

May 11th, 2011 subogero No comments

I’m always very proud how incredibly easily my Linux systems cooperate with the external world, including Windows machines.

For instance, just now, after one day of searching, sweating and swearing, I was able to mount some Windows shares onto a Debian virtual server.

For those of you who boast that one can do this with two clicks in Windows, let me tell you that

  1. it’s actually 6 clicks
  2. I also could have used Nautilus and just connect to a server

But that would have been too easy and, at the same time, too difficult to use. Have you ever seen such a Gnome gvfs mount point?

~/.gvfs/My bloody space-separated sharename on Foo

Brrrr. One wants something nice like

~/Foo

One also wants to be able to mount and unmount it as a normal user. And to have write access. And not having to enter a password, but also not to reveal it to others. One is very picky.

Before all, don’t forget to create the mount point directory manually. It shall be world-executable as well.

$ mkdir ~/Foo
$ chmod 775 ~/Foo

Now let’s see the /etc/fstab entry. We’ll explain every option later.

//srv/share /home/foo/Foo cifs rw,user,credentials=/home/foo/.foo,uid=1000,gid=1000 0 0

The entries are share UNC path, mount point, file system type, options, etc.

If you miss anything from the dreaded options, you’ll get the following highly informative error message when trying the mount:

mount error(13): Permission denied

Option “rw” means read-write. Easy.

Option “user” means not only root is allowed to mount or unmount the share.

Server “srv” is in domain “bar” and shares “share” for user “baz” whose password is “spam”. We could add these options directly to fstab (username=bar,password=spam,domain=baz), but that would make it world readable. Instead the info is stored in a credentials file in Linux user foo’s home. Make sure this file is readable by foo only. Let’s see its contents too:

$ chmod 600 ~/.foo
$ ls -l ~/.foo
-rw------- 1 foo foo size date .foo
$ cat ~/.foo
username=bar
domain=baz
password=spam

Don’t put any whitespace around the “=” signs. There is a school of thought that there should not be any character after the end of the password, not even a newline.

And last but not least, the Linux user’s user and group IDs should be specified as well. In our case “foo” is the first normal user on this machine, that’s why it’s 1000.

Now user foo should be able to mount and unmount the above share:

$ mount ~/Foo
$ umount ~/Foo
Categories: Uncategorized Tags: , , , ,