aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-06-19 11:47:05 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-06-19 11:47:05 +0200
commit10a3fb33824a239b0390203bea1aa4019525ec0c (patch)
tree9f9ad33a285cfce6f7689beebf42144916951e31
parent6bf27664f8580430751f46c9d0bef474a0835fab (diff)
downloaddwim-10a3fb33824a239b0390203bea1aa4019525ec0c.tar.gz
Sort subroutine definitions alphabetically
-rwxr-xr-xdwim63
1 files changed, 31 insertions, 32 deletions
diff --git a/dwim b/dwim
index 33953c0..1e736cf 100755
--- a/dwim
+++ b/dwim
@@ -7,6 +7,16 @@ use warnings;
use strict;
use subs qw/arguments dir env fail handle path run/;
+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 = ('rox');
+my @MAILDIR_VIEWER = (@OPENER, 'mutt -f');
+my $MAILROOT = env MAILROOT => '/home/john/mail/';
+
my ($DEBUG, $handler, $phrase);
while ($_ = shift @ARGV) {
@@ -21,16 +31,6 @@ while ($_ = shift @ARGV) {
$phrase = `xsel -o` if not defined $phrase;
-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 = ('rox');
-my @MAILDIR_VIEWER = (@OPENER, 'mutt -f');
-my $MAILROOT = env MAILROOT => '/home/john/mail/';
-
for ($phrase) {
if (/^(https?:\/?\/?\S+)$/) {
handle 'web address';
@@ -134,17 +134,12 @@ sub dir {
die "couldn't retrieve current directory: xtitle not installed\n";
}
-# path -- return absolute path to file (and chdir to its directory)
-sub path {
- my $n = shift;
- $n =~ s,^~([^/]+),/home/$1,;
- $n =~ s,^~,/home/$ENV{USER},;
- goto done if $n =~ /^\// or $n =~ /^~/;
- $n = dir . "/$n";
-done: chdir dirname($n);
- return $n;
+# dirname -- return path without last part
+sub dirname {
+ my $path = shift;
+ $path =~ s,/[^/]+$,,;
+ return $path;
}
-
# env -- for (K => V), return environment variable K if defined, otherwise V
sub env {
my %h = @_;
@@ -153,16 +148,27 @@ sub env {
return $h{$k};
}
-# handle -- print debug message when handler matches
+# fail -- print debug message when matched handler fails
+sub fail {
+ my $msg = shift;
+ print STDERR "$handler FAILED: $msg\n";
+}
+
+# handle -- save matched handler and print debug message
sub handle {
$handler = shift;
print STDERR "$handler MATCHED\n" if $DEBUG;
}
-# fail -- print debug message when matched handler fails
-sub fail {
- my $msg = shift;
- print STDERR "$handler FAILED: $msg\n";
+# path -- return absolute path to file (and chdir to its directory)
+sub path {
+ my $n = shift;
+ $n =~ s,^~([^/]+),/home/$1,;
+ $n =~ s,^~,/home/$ENV{USER},;
+ goto done if $n =~ /^\// or $n =~ /^~/;
+ $n = dir . "/$n";
+done: chdir dirname($n);
+ return $n;
}
# run -- launch program and quit
@@ -178,10 +184,3 @@ sub run {
}
exit;
}
-
-# dirname -- return path without last part
-sub dirname {
- my $path = shift;
- $path =~ s,/[^/]+$,,;
- return $path;
-}