#!/usr/bin/perl -w # # Copyright (C) 2009 Alex Linke, # # This script is provided under the terms of the MIT license. # use strict; ## Where are the lyrics stored? my $basedir = join("/", $ENV{HOME}, ".lyrics"); die "usage: $0 artist title\n" unless scalar(@ARGV) == 2; my @filenames = (get_filenames(" - ", @ARGV), get_filenames("__", @ARGV)); foreach my $file (@filenames) { my $path = "$basedir/$file.txt"; if (-e $path) { open FH, $path or die "$path: $!\n"; local $/; print ; close FH; exit(0); } } exit(69); ## Build a set of possible filenames sub get_filenames { my $sep = shift(); my $f = join($sep, @_); my @fns = ($f); push @fns, lc($f), uc($f); push @fns, join(" ", map { ucfirst } split(/\s+/, $f)); for (my ($i, $last) = (0, $#fns); $i <= $last; $i++) { ($_ = $fns[$i]) =~ s/\s+/_/g; push @fns, $_; } return @fns; } # vim: sts=4 sw=4 enc=utf-8 ai et