Preventing the Meta key from opening the dash in Unity Ubuntu

Everytime I install Ubuntu on a fresh computer and try to define custom keybindings that use the meta (ie. Windows) key, I run into issues.

The Ubuntu UI uses the meta key to open what they call the "Dash". I never use it and want my meta key back to define my own keybindings.

There is no way to disable it from the default Ubuntu options. You have to install compizconfig-settings-manager and launch it using ccsm. There, go to the Ubuntu Unity Plugin and disable the "Key to show the launcher" binding.

You will now be free to use the meta key in your keybindings, again.

git resurrect to bring back deleted files from the dead

Ever deleted a file several commits away and then suddenly realizing that you actually need it ? Well, here's an easy way to get your file back.

First of all, we'll get the commit in which the file has been deleted with : git log --diff-filter=D --format=format:%H -- {your_filename}

--diff-filter=D will only keep commits where files gets deleted, --format=format:%H will only display the commit hash and finally the -- is a separator between your options and the argument. Argument should be your filename, and it even accepts * as a wildcard.

Once you got the commit hash, it's just a matter of checking the file out using git checkout {hash}~1 {your_filename}. The ~1 targets the previous commit, right before the file gets deleted.

All wrapped up in a nice shell script, here is what it looks like :

#!/usr/bin/env bash
filename=$1
# We first find the commit where the file was deleted
hash=$(git log --diff-filter=D --format=format:%H -- $filename)
# We then bring it back from the dead
git checkout $hash~1 $filename

I've aliased mine to git resurrect.

Renaming files to fit on a FAT32 drive

When moving files from my hard-drive (formatted in ext3) to my mp3 music player or to any drive formatted in FAT32, some files never get to the destination due to illegal characters in their filename.

Those includes characters like question marks, colons or quotes which can be quite common in media filenames.

So I wrote myself a tiny command-line script to make the filenames FTA32 compliant. Note that this is a destructive operation as it will simply remove the illegal characters.

Converting files to UTF-8 from the command line

Converting to and from charset encoding is boring. Life would be much easier if everything was saved in proper UTF-8.

I just coded a couple of scripts that will help be read file encoding from files and convert them to UTF-8.

First, not all encoding can be easily read. Some uses markers that are easy to check, other requires heuristic and guessing. I won't deal with the second part. Most of the files I'm currently handling are either Latin1 (ISO-8859-1) or Latin2 (ISO-8859-2), so I'll limit the scope of my scripts to those two sets.

Fortunatly, the default file command can do that.

$ file -bi file.txt
text/plain; charset=us-ascii
$ file -bi bad.html
text/html; charset=iso-8859-1
$ file -bi good.html
text/html; charset=utf-8

Now that we have a way to know the input encoding, we can use recode to convert to UTF-8. You can install recode easily with sudo apt-get install recode.

Once done, it is just a matter of convert latin1..utf8 bad.html

I wrapped those methods in two scripts : encoding and utf8 that respectively output the file encoding and convert the file to utf8.

Downloading from Youtube for offline watching

Call me old fashioned but I do not really like the "always connected" motto that the industry is following right now. I like to have physical music and video files on my hard drive, so I can access them anywhere, anytime, without relying on me being connected to a network.

And yes, I get the irony of talking about physical _files._

Anyway, I now download movies directly from Youtube, Dailymotion, Vimeo and consorts, copy them to my smartphone, and watch them in the train, waiting queues or bed.

To achieve that, here are the command-line tools I'm using. First is youtube- dl, and as its name does not imply at all, it can download from more than Youtube. The second one is vimeo_downloader which is specialised in downloading from Vimeo. And the last one is the more generic getflashvideos that can download from a variety of smaller websites.

All those scripts accepts the video url as parameter.

Happy scripting and happy viewing !