aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdwim47
1 files changed, 29 insertions, 18 deletions
diff --git a/dwim b/dwim
index 7d3afcd..a536abb 100755
--- a/dwim
+++ b/dwim
@@ -11,13 +11,15 @@ use subs qw/path env handle fail run arguments/;
my ($phrase, %o) = arguments "usage: $0 parse\n", 1, d => 0;
$phrase = `xsel -o` if not defined $phrase;
-my @OPENER = split /\s/, env OPENER => "xterm -e";
-my @EDITOR = split /\s/, env EDITOR => "vi";
-my @MAILER = split /\s/, env MAILER => "mutt";
-my @BROWSER = split /\s/, env BROWSER => "w3m -title";
-my @FILE_BROWSER = split /\s/, env FILE_BROWSER => "noice";
-my @MAILDIR_VIEWER = split /\s/, env MAILDIR_VIEWER => "mutt -f";
-my $MAILROOT = env MAILROOT => "/home/john/mail/";
+my @OPENER = ("xtopen");
+my @EDITOR = (@OPENER, "vi");
+my @PDF_VIEWER = ("xpdf");
+my @MAN_VIEWER = (@OPENER, "man");
+my @MAILER = (@OPENER, "mutt");
+my @BROWSER = (@OPENER, "w3m -title");
+my @FILE_BROWSER = (@OPENER, "noice");
+my @MAILDIR_VIEWER = (@OPENER, "mutt -f");
+my $MAILROOT = env MAILROOT => "/home/john/mail/";
our $handler;
@@ -35,39 +37,47 @@ for ($phrase) {
if (/^(.+?):(\d+).*?$/) {
handle "file:line (like grep -n)";
my $p = path $1;
- run @OPENER, @EDITOR, "-c", ":$2", "$p"
+ run @EDITOR, "+$2", "$p"
}
if (/^(.+) line (\d+)\.?$/) {
handle "FILE line LINE (like perl)";
my $p = path $1;
- run @OPENER, @EDITOR, "-c", ":$2", "$p"
+ run @EDITOR, "+$2", "$p"
}
if (/^(.+):(.+)$/) {
handle "file:query (like grep)";
my $p = path $1;
- run @OPENER, @EDITOR, "-c", "/$2", "$p" if -e $p;
+ run @EDITOR, "+/$2", "$p" if -e $p;
fail "file not found" if $o{d};
# otherwise fall through
}
if (/^(\S+)\((\S+)\)[,.]?/) {
handle "manpage(section)";
- run @OPENER, "man", $2, $1;
+ run @MAN_VIEWER, $2, $1;
}
if (/^(\S+)\.([1-9])/) {
handle "manpage.section";
my $p = path "$1.$2";
- run @OPENER, "man", $p if -e $p;
- run @OPENER, "man", $2, $1;
+ run @MAN_VIEWER, $p if -e $p;
+ run @MAN_VIEWER, $2, $1;
}
if (/^<(\S+)>$/) {
handle "<header.h>";
- run @OPENER, @EDITOR, "/usr/include/$1" if -e "/usr/include/$1";
- run @OPENER, @EDITOR, "/usr/local/include/$1" if -e "/usr/local/include/$1";
+ open my $h, 'find / -maxdepth 3 -type d -name include 2>&-|'
+ or fail "could not search include directories";
+ while (<$h>) {
+ chomp;
+ if (-e "$_/$1") {
+ close $h;
+ run @EDITOR, "$_/$1";
+ }
+ }
+ close $h;
fail "header file not found";
}
@@ -79,9 +89,10 @@ for ($phrase) {
if (/^(\S+)$/) {
handle "maildir / directory / file";
my $p = path $1;
- run @OPENER, @MAILDIR_VIEWER, "$p" if $p =~ /^$MAILROOT/; # maildir
- run @OPENER, @FILE_BROWSER, "$p" if -d $p; # directory
- run @OPENER, @EDITOR, "$p" if -e $p; # file
+ run @MAILDIR_VIEWER, "$p" if $p =~ /^$MAILROOT/; # maildir
+ run @FILE_BROWSER, "$p" if -d $p; # directory
+ run @PDF_VIEWER, "$p" if -e $p and $p =~ /\.pdf$/; # pdf
+ run @EDITOR, "$p" if -e $p; # file
fail "file not found" if $o{d};
# otherwise fall through
}