aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-27 00:34:31 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-27 00:35:59 +0200
commit4cf17da6e7e7afc01694eacd85358c480b79c42c (patch)
tree34c1d88d807d18d741612cb64f29b17c8c901c59
parent42d01da96f85c6e2de6e6061aa418d4aa8a64441 (diff)
downloaddwim-4cf17da6e7e7afc01694eacd85358c480b79c42c.tar.gz
dwim: Add -o (use OPENER) option
-rwxr-xr-xdwim30
-rw-r--r--dwim.16
-rw-r--r--xchord.c2
3 files changed, 23 insertions, 15 deletions
diff --git a/dwim b/dwim
index a3224cb..04e2632 100755
--- a/dwim
+++ b/dwim
@@ -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";
}
diff --git a/dwim.1 b/dwim.1
index d2e95fa..e67bc7a 100644
--- a/dwim.1
+++ b/dwim.1
@@ -8,6 +8,7 @@
.Sh SYNOPSIS
.Nm dwim
.Op Fl d
+.Op Fl o
.Op Ar phrase
.
.Sh DESCRIPTION
@@ -98,6 +99,11 @@ or equivalent)
.It MAILDIR_VIEWER
.Li OPENER mutt -f
.El
+.Pp
+.Li OPENER
+is only used if the
+.Fl o
+flag is specified.
.Sh AUTHORS
.An -nosplit
.An John Ankarström Aq Mt "john (at) ankarstrom.se"
diff --git a/xchord.c b/xchord.c
index 970c141..c4f6f47 100644
--- a/xchord.c
+++ b/xchord.c
@@ -82,7 +82,7 @@ main(int argc, char *argv[])
/* 1 pressed + 3 pressed + 3 released (third step) */
if(p == 2 && rev->detail == 3){
p = 3;
- system("dwim");
+ system("dwim -o");
}
/* 1 released (reset) */
if((p == 1 || p == 3) && rev->detail == 1) p = 0;