From 10a3fb33824a239b0390203bea1aa4019525ec0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 19 Jun 2021 11:47:05 +0200 Subject: Sort subroutine definitions alphabetically --- dwim | 63 +++++++++++++++++++++++++++++++-------------------------------- 1 file 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; -} -- cgit v1.2.3