S T A R T
the end of your starting problems :-)
#!/usr/bin/perl
# This script uses an "extensions:handler" file to start
# the appropriate program for handling files with various
# extensions.
# Usage start [-a] file1 file2 ...
# Use -a for opening in background.
# The program is licensed GNU GPL version 2 or later.
# See GPL.txt or an online version of the license.
use strict;
# This could very well be the only thing you'd have to
change, if any.
my $extensions_file = $ENV{"HOME"} . "/.extensions";
my @args;
my @filename;
my $arg;
my $extensions;
my $fullcmd;
my $failmsg = "Could not execute ";
open(EXTENSIONS, "< $extensions_file");
$extensions = do { local $/; <EXTENSIONS> };
foreach $arg (@ARGV) {
if($arg =~ s/(((\S|\s)+)\.(\S+))//) {
@filename = ($1);
if($extensions =~ m/$4\,.*\:((\S|\s)+?)\n/) {
@args = (split(/ /, $1), @filename);
print $fullcmd = join(" ", @args) . "\n";
if($ARGV[0] eq "-a") {
if(!fork()) {
exec(@args) == 0 or die $failmsg . $fullcmd;
}
} else {
system(@args) == 0 or die $failmsg . $fullcmd;
}
}
}
}
# Here's a sample ~/.extensions file.
#-----8<------CUT HERE---------------
#exe,EXE,Exe,:wine
#htm,html,HTM,HTML,:opera
#png,PNG,jpg,jpeg,JPG,JPEG,Jpeg,Jpg,gif,GIF,tga,TGA,:ee
#c,cpp,C,CPP,java,:xemacs
#dvd,avi,AVI,mpg,mpeg,MPG,Mpeg,wmv,mov,ram,:mplayer -fs
#rtf,RTF,Rtf,:abiword
#pdf,PDF,:/usr/local/Acrobat4/bin/acroread
#dvi,DVI,:xdvi
#ps,PS,:gv
#mp3,MP3,:mpg123
#cab,:cabextract
#rar,:rar x
#doc,DOC,Doc:abiword
#-----8<------CUT HERE---------------