aboutsummaryrefslogtreecommitdiff
path: root/xtopen
blob: 3b698a858d8881882aaa3242bdf49ecd43d83a94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/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 [-i] [-k] [-K] [-u] cmd ..."
	exit 1
fi

i=
k=
K=
u=
while getopts ikKu o; do
	case $o in
	i)	i=1 ;;
	K)	K=1 ;;
	k)	k=1 ;;
	u)	u=1 ;;
	?)	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

prefix=

[ ! -z "$i" ] && prefix=$prefix\ iso8859-1
[ ! -z "$u" ] && prefix=$prefix\ utf8

case "$k,$K" in
1,*)	prefix=$prefix\ with-shell ;;
*,1)	prefix=$prefix\ with-shell-on-error ;;
esac

exec xterm -title "$* (`abbr "$PWD"`)" -e $prefix "$@"