aboutsummaryrefslogtreecommitdiff
path: root/dwim.sh
diff options
context:
space:
mode:
authorJohn <john@ankarstrom.se>2019-06-01 13:54:57 +0200
committerJohn <john@ankarstrom.se>2019-06-01 14:04:06 +0200
commit99315219aba0481466c8bb236548284ccec5a1d5 (patch)
treeb8d34b92e746019ce8c75afa0402c0d378870d75 /dwim.sh
parent21ee94842b6e461b0cd4536557f9a5a2776132aa (diff)
downloaddwim-99315219aba0481466c8bb236548284ccec5a1d5.tar.gz
dwim.pl
This is the Perl version of dwim. It is much easier to work with and extend, thanks to Perl's excellent regex support. The "phrase" (either $ARGV[0] or the primary X selection) is matched against regular expressions in the for loop (a primitive switch statement). This is the place to add handlers. Options are specified through environment variables, defined with default values in the section before the handlers. The `path` subroutine transforms a relative path to an absolute path based on the title of the current window. It depends on the `xtitle` program, and for it to work, you must instruct your shell (or editor) to set the terminal's title to the current directory (or currently edited file). (As such, `path` doesn't work with other programs than terminals and editors.)
Diffstat (limited to 'dwim.sh')
-rwxr-xr-xdwim.sh39
1 files changed, 0 insertions, 39 deletions
diff --git a/dwim.sh b/dwim.sh
deleted file mode 100755
index 64f7773..0000000
--- a/dwim.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/sh
-
-# dwim (do what i mean) is my own plan9-like plumber
-
-err() { echo "$@" 1>&2; exit 1; }
-usage="$0 phrase"
-
-[ $# -gt 1 ] && err "$usage"
-[ $# -eq 1 ] && p=$1 || p=$(xsel -o)
-[ -z "$p" ] && err "$usage"
-
-[ -z "$OPENER" ] && OPENER=u
-
-case "$p" in
-*:*)
- file=${p%%:*}
- line=${p#*:}; line=${line%:}
-
- dir=
- case "$file" in
- /*) ;;
- ~*) ;;
- *)
- dir=$(xtitle)/
- [ ! -d "$dir" ] && err "couldn't retrieve directory"
- ;;
- esac
-
- exec "$OPENER" "$EDITOR" -c ":$line" "$dir$file"
- ;;
-/*)
- exec "$OPENER" "$EDITOR" "${p%:}"
- ;;
-~*)
- exec "$OPENER" "$EDITOR" "${p%:}"
- ;;
-esac
-
-err "no handler matched"