A one-liner to catch'em all!

Posted: August 16, 2015
Categories: debian, debsources, hack

I wrote a Bash one-liner to open the source code (in Debsources) of any file on your system (if it belongs to a Debian package).

It will simply retrieve the associated package and point your default browser to its source code.

Add this somewhere in your $PATH, and name this file debsrc:

#!/bin/bash

function debsrc {
    readlink -f $1 | xargs dpkg-query --search | cut -d: -f1 | xargs apt-cache showsrc | head -n 1 | grep-dctrl -s 'Package' -n '' | awk -F " " '{print "http://sources.debian.net/src/"$1"/latest/"}' | xargs x-www-browser
}

CMD="$1"
debsrc ${CMD}

And try something like debsrc /usr/share/doc/acpi/AUTHORS. Enjoy!

Update: improved the one-liner thanks to josch's advice.