Wednesday, 17 December 2008

Cygwin, Emacs, Unix on Windows

My new work-place is pretty much a windows-only shop, but I miss having a nice command-line, Perl and emacs to hand.
Though I could get most these things separately I've installed Cygwin and it's quite Joe-Lush. Just run the set-up from the website. Probably best to install some extra packages rather than just the basics; I went for:
  • emacs (for editing)
  • emacs-X11
  • nano (for basic editing)
  • perl (for everything)
  • xclock (for testing X)
If you can bear it, install in C:/cygwin as suggested, it makes things easier. Probably a good idea to copy the setup.exe to the same folder afterwards since you'll be wanting to install more packages at some point, and for this you need setup.exe.

X-server

A few things need tweaking out of the box. Firstly an X-server. If you want to use graphical apps you'll need one of these. Cygwin does come with an X-server but I always found it a bit fiddly; try Xming, it's ace. You need to install it and start it running. It won't do anything much itself, it'll just sit there in the background waiting to display any X applications.

Home Directory

Under Windows XP your default home dir will probably be in the "Documents and Settings" folder. Spaces in your home dir path will most likely cause problems, so change it. Start up cygwin, and create yourself a home directory (e.g. mkdir /home/justin), then edit your /etc/passwd file - you should be able to work out which part of the line to edit for your user (probably the last one), but be careful, if you screw this up there's no easy way to fix it. I'd suggest using the nano editor:
nano /etc/passwd

Setting DISPLAY

To use X you'll need to set your DISPLAY environment variable. Do it from the the command line:
export DISPLAY=localhost:0
It's probably easier to create a .bashrc file in your home dir and add this line to it. Which leads us to...

BASHRC

For some reason your .bashrc might not get read on start-up. Fix this by adding:
. ${HOME}/.bashrc
to your /etc/profile file (note the dot at the start of that line).

Terminal & Putty-for-Cygwin

The terminal emulator that comes with Cygwin is not that great; resizing is nasty, copying and pasting is worse. I use Putty when SSHing around from Windows and it turns out someone has patched Putty to work with Cygwin, god bless them. Take a look at PuttyCyg - download it and copy the 3 or 4 files in the zip file to C:/cygwin/puttycyg for example. Then run puttycyg and save a cygwin session or run directly by creating a Windows short-cut, and within properties set the Target to
C:\cygwin\puttycyg\putty.exe -cygterm -
Perfect.

Fonts

Finally you'll obviously be wanting to use 6x13 as your font, the acknowledged King of Fonts. Get it for Windows from http://www.ank.com.ar/fonts.

Monday, 13 October 2008

Ex Falso - MP3 Tag Editor

I've just discovered Ex Falso, a GUI-based audio-file tag editor (MP3s and everything else). You can manually add and edit tags, create tags based on file names, rename files based on tags, add sequential track numbers, all the general things you need. It's part of the Quod Libet media player, but if you're happy with your media player you can use the Ex Falso editor as stand-alone.

It's a GTK+ app, written in Python and is in the standard Ubuntu repositories:
sudo apt-get install exfalso

Tuesday, 19 August 2008

Sync Google Contacts with Thunderbird

I use Thunderbird as my email client of choice, and I use it to access my Googlemail account via imap. Everything works just splendidly, except for sharing contacts.

Fortunately I've found Zindus, a rather splendid add-on for Thunderbird that keeps your Thunderbird and Google contacts in sync. Everything you need is to be found on the Zindus website, but it seems pretty idiot-proof, and so far seems to work just like it ought to. Well done Zindus.

Normalise Volume of Quiet mp3 Files

Got some quiet mp3 files? These can be easily fixed with the normalize-audio package in Ubunutu. Install with:
sudo apt-get install normalize-audio
then run as:
normalize-audio -v myfile.mp3
where the -v just gives some verbose output.

If you have several files you want to normalise to the same level use the --mix switch; this will adjust quiet files more than average files. To apply the same amount of volume correction to several files use the --batch switch. E.g.:
normalize-audio -v --mix *MyAlbum*.mp3

Monday, 18 August 2008

Controlling MPD with a media keyboard in Ubuntu

I've switched to using MPD as my music-player under Ubuntu. It's very lightweight, and allows me to control the playing music from my desktop on the Ubuntu box, or from my laptop (using the superb Minion firefox addon). Note that MPD is just a daemon that sits in the background playing music, you need something like Minion to control it.

My keyboard is a wireless S510 keyboard, with accompanying wireless mouse and 'media remote'. I'd like to use this to control MPD, so the 'media buttons' i.e. the play/pause, stop, previous and next buttons, all control MPD.

The easiest way to achieve this is to use xbindkeys along with mpc, a command-line mpd client. With mpc you can control mpd by issuing command like mpc next or mpc stop. Xbindkeys allows you to fire off custom commands when you hit certain buttons.

To use xbindkeys you need to find the 'key codes' that correspond to your media keys. Hopefully the codes I show below should work for you, but if not try running the xev command from a terminal, press the media keys and look at the output. Looking below you can see that key-code 153 corresponds to the 'next track' button, for example. Once you have the key-codes enter the following into your ~/.xbindkeysrc file.

"/usr/bin/mpc toggle"
c:162

"/usr/bin/mpc next"
c:153

"/usr/bin/mpc prev"
c:144

"/usr/bin/mpc stop"
c:164

Note that "mpc toggle" toggles the play/pause state of mpd. Also note that I've left Gnome controlling the volume since it does a fine job already.

The last job to do (if you're using Gnome, as is the default in Ubuntu) is to stop Gnome from grabbing the keypresses from the media buttons. Otherwise xbindkeys will never see the keypresses. Do this using the following 4 gconftool commands (the word-wrap looks screwed up, copy & paste should work?):

gconftool-2 --set /apps/gnome_settings_daemon/keybindings/next --type string disabled

gconftool-2 --set /apps/gnome_settings_daemon/keybindings/previous --type string disabled

gconftool-2 --set /apps/gnome_settings_daemon/keybindings/play --type string disabled

gconftool-2 --set /apps/gnome_settings_daemon/keybindings/stop --type string disabled

So given you have your ~/.xbindkeysrc file set-up, run xbindkeys and everything should work. Note that by default xbindkeys runs as a daemon in the background, so for debugging try xbindkeys -n -v to allow you to see the debugging messages.

Once it's all working you should add xbindkeys to start automatically when you log in. In Gnome go to System -> Preferences -> Sessions -> Startup Programs. Add an entry for xbindkeys.

A final note concerning using passwords, mpd and mpc. I use a password with my mpd (very weak security but still...). For mpd to use passwords you need to set the MPD_HOST env variable. Do this in your ~/.bashrc and your ~/.gnomerc files by adding the following command (it's likely you won't have a .gnomerc file so create one). The .bashrc entry ensures mpc works from terminal and ssh sessions, the latter ensures that mpc can see the env variable when it is kicked off by xbindkeys. This is the line to add to those two files:
export MPD_HOST=MyPassword@localhost