~dricottone/my-utils

ref: 0fc0112189c80cb24b03ed1a9b8631466657c637 my-utils/src/whiched -rwxr-xr-x 914 bytes
0fc01121Dominic Ricottone Added tarls; Update to mktar for archiving directories 4 years ago
                                                                                
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
#!/bin/sh

name="whiched"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Open a program with your editor
	Usage: whiched PROGRAM [OPTIONS]
	Options:
	 -h, --help     print this message
	 -q, --quiet    suppress error messages
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

# open first non-option argument in editor, then exit
for arg; do
  case "$arg" in
  -q|--quiet)
    #ignore these
    ;;

  *)
    # main routine
    target=$(command -v "$arg")
    if [ -z "$target" ]; then
      if [ "$quiet" -eq 0 ]; then
        (>&2 printf "%s: No such directory '%s'\n" "$name" "$target")
      fi
      exit 1
    else
      my_editor=${EDITOR:=/usr/bin/ed}
      $my_editor "$target"
      exit $?
    fi
    ;;
  esac
done

# if have not exited, no program was specified
if [ "$quiet" -eq 0 ]; then
  (>&2 /usr/bin/printf "Usage: whiched PROGRAM [OPTIONS]\n")
fi
exit 1