aboutsummaryrefslogtreecommitdiff
path: root/etc/xtopen
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-12 13:24:49 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-12 13:27:07 +0200
commit03d827e2fbc409ef97829f25b8eeca5204f81a3c (patch)
tree6099f0feb9adf3425fba87549b164043e18bd0c7 /etc/xtopen
parent45cddd072119c5abd7ec076cf28d51ee01f125b7 (diff)
downloadxutil-03d827e2fbc409ef97829f25b8eeca5204f81a3c.tar.gz
Re-organize files
Diffstat (limited to 'etc/xtopen')
-rwxr-xr-xetc/xtopen41
1 files changed, 41 insertions, 0 deletions
diff --git a/etc/xtopen b/etc/xtopen
new file mode 100755
index 0000000..ccda2e5
--- /dev/null
+++ b/etc/xtopen
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# xtopen -- run command in xterm
+
+abbr() {
+ case "$1" in
+ /home/$USER/*) a='~'${1#/home/$USER} ;;
+ /home/$USER) a='~' ;;
+ /home/*) a='~'${1#/home/} ;;
+ *) a=$1 ;;
+ esac
+ printf '%s\n' "$a"
+}
+
+if [ $# -eq 0 ]; then
+ xmessage -buttons sorry:0 -default sorry -nearmouse \
+ "usage: $0 [-o xterm-opt] [-p prefix] cmd ..."
+ exit 1
+fi
+
+o=
+p=
+while getopts o:p: opt; do
+ case $opt in
+ o) o=$OPTARG ;;
+ p) p=$OPTARG ;;
+ ?) xmessage -buttons sorry:0 -default sorry -nearmouse \
+ error: "unknown flag $1"
+ exit 1 ;;
+ esac
+done
+shift $((OPTIND-1))
+
+if ! which "$1" >/dev/null; then
+ xmessage -default okay -nearmouse \
+ error: "program $1 not found"
+ exit 1
+fi
+
+export LC_ALL=en_US.ISO8859-1 # speed up xterm start
+exec xterm -title "$* (`abbr "$PWD"`)" $o -e u $p "$@"