diff options
Diffstat (limited to 'dwim')
-rwxr-xr-x | dwim | 30 |
1 files changed, 16 insertions, 14 deletions
@@ -7,7 +7,21 @@ use warnings; use strict; use subs qw/cd dir dirname env fail handle path run/; -my @OPENER = ('xtopen'); +my ($cwd, $handler, $phrase); +my ($DEBUG, $OPENER); + +while ($_ = shift @ARGV) { + if (/^-/) { + $DEBUG = 1 if /d/; + $OPENER = 1 if /o/; + die "usage: $0 [-d] [phrase]\n" if not /[do]/ + } else { + $phrase = $_; + last; + } +} + +my @OPENER = $OPENER ? ('xtopen') : (); my @EDITOR = (@OPENER, 'vi'); my @PDF_VIEWER = ('xpdf'); my @MAN_VIEWER = (@OPENER, 'man'); @@ -17,18 +31,6 @@ my @FILE_BROWSER = ('rox'); my @MAILDIR_VIEWER = (@OPENER, 'mutt -f'); my $MAILROOT = env MAILROOT => '/home/john/mail/'; -my ($DEBUG, $cwd, $handler, $phrase); - -while ($_ = shift @ARGV) { - if (/^-d$/) { - $DEBUG = 1; - } elsif (/^-/) { - die "usage: $0 [-d] [phrase]\n"; - } else { - $phrase = $_; - } -} - $phrase = `xsel -o` if not defined $phrase; for ($phrase) { @@ -202,7 +204,7 @@ sub run { s/(\s)/\\$1/g for @argv; # escape whitespace print STDERR "@argv\n"; } - if (fork == 0) { + if (!$OPENER or fork == 0) { exec @_; die "could not exec: $1\n"; } |