aboutsummaryrefslogtreecommitdiff
DWIM(1) General Commands Manual DWIM(1)

dwim
do what I mean with a given phrase (file, URL etc.)

dwim [-d] [-o] [phrase]

dwim is a program similar to Plan 9's plumber. It takes a string (phrase) and matches it against a number of regular expressions, which are connected to handlers, specifying what to do with the phrase.

If no phrase is given, the current X selection is retrieved from xsel(1). This is surprisingly useful. If you assign a shortcut key to invoke dwim in your window manager, you can select a string of text, press the shortcut key and dwim will act on the selected text.

If the xtitle program is installed on the system, dwim will try to figure out the current working directory from the window title. The following title formats are recognized:

  1. path
  2. program (path)

Tilde expansion is supported.

Open Makefile in the configured text editor:
$ ls
LICENSE   Makefile  README.md repl      repl.1    repl.c
$ dwim Makefile

If we represent the current X selection with bold text, the following procedure opens message-window.lisp on line 164 in the configured text editor:
$ grep -n 'def.*indicator ' *.lisp
message-window.lisp:164:(defun show-frame-indicator (group &optional force)
$ dwim

dwim is configured by editing the source code. It is a simple Perl script, which uses regular expressions to parse phrases. Default programs are defined at the top of the script. The following associations are defined by default:
OPENER
(change this to xterm -e or equivalent)
EDITOR
PDF_VIEWER
MAN_VIEWER
MAILER
BROWSER
FILE_BROWSER
MAILDIR_VIEWER

OPENER is only used if the -o flag is specified.

John Ankarström <john (at) ankarstrom.se>
October 23, 2021 NetBSD 9.1