Archive for January, 2013

I have been meaning to write this post for a long time.

One thing which I often found myself doing was typing echo $? after running a command to find out if there was any error, or appending || echo failed to the end of the command line.

Commands generally warn if there was an error, but you have to stop for a second and carefully read the output to see whether anything went wrong. I’m lazy and that additional second and the extra cognitive effort always bothered me.

I eventually had the idea of making the shell prompt show the exit status of the last command if it was non-zero. I use zsh, so it’s got to be possible. 🙂

It turns out it is, this is my PS1 variable now:


export PS1="${CYAN}%m${NORM}%# %(?..${RED}(%?%)${NORM} )"

The magical part is %(?..${RED}(%?%)${NORM} ). Here’s the result:

zsh prompt

As a side note, one other thing that the screenshot shows is the right-hand prompt. This is a great feature of zsh, and I use it to show the current working directory. That way, no matter where I am in the filesystem, the cursor prompt always starts at the same column. Here’s my RPS1 variable:


export RPS1="${MAGENTA}%~${NORM}"


Read Full Post »

Since version 2.6, you can tell Amarok to convert (transcode) every music track to MP3 when copying it to a given device.

There’s a bug, however which causes MP3 files converted from Ogg Vorbis to lose all metadata (artist, album, title etc). This is a showstopper for me.

This happens because Amarok needs to pass an option to ffmpeg to tell it to get the metadata from the first stream found in the Ogg file as opposed to the default of getting it from global metadata. Unfortunately as far as I can tell there’s no way to configure the ffmpeg command line used by Amarok. The solution then is to replace the ffmpeg binary in the path with a script that will do that, like this one:

import os
import sys

AVCONV_FFMPEG = '/usr/bin/ffmpeg.distrib'
os.execv(AVCONV_FFMPEG, sys.argv + ['-map_metadata', '0:0,s0'])

In Debian or Ubuntu, you can divert the real ffmpeg binary and install the script above as /usr/bin/ffmpeg:

$ sudo dpkg-divert --add /usr/bin/ffmpeg
$ sudo cp /tmp/fake-ffmpeg.py /usr/bin/ffmpeg
$ sudo chmod +x /usr/bin/ffmpeg

There’s another bug where Amarok needlessly converts even MP3 files when copying them to the device.

Read Full Post »