-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-i
executable file
·64 lines (55 loc) · 1 KB
/
find-i
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
55
56
57
58
59
60
61
62
63
64
#! /bin/bash
function usage {
echo 1>&2 "Usage: $0 [-d] scriptname.bash"
echo 1>&2 "-a - strip letters from end"
echo 1>&2 "-d - print path to data directory"
echo 1>&2 "-h - this message"
exit "$@"
}
while getopts 'adh' opt ; do
case "$opt" in
a) opt_a=1 ;;
d) opt_d=1 ;;
h) opt_h=1 ;;
\?) usage 1 ;;
*) echo "Can't happen" ; exit 1 ;;
esac
done
shift $((OPTIND-1))
if [ "$opt_h" ] ; then
usage
fi
if [ -z "$1" -o "$2" ] ; then
usage 1
fi
NAME="$1"
case "$NAME" in
*.bash) NAME="$(basename "$NAME" .bash)" ;;
*.sh) NAME="$(basename "$NAME" .sh)" ;;
*) :
esac
case "$NAME" in
doit*-*)
X=$(echo "$NAME" | sed -r -e 's/^doit([^-]+)-.*/\1/')
SEP=
;;
doit*)
X=$(echo "$NAME" | sed -e 's/^doit//')
SEP=
;;
*)
X=$(echo "$NAME" | sed -e 's/ /_/g')
SEP=_
esac
if [ "$opt_a" ] ; then
X=$(echo "$X" | sed -r -e 's/[a-z]+$//')
fi
if [ "$opt_d" ] ; then
if [ -z "$X" ] ; then
echo data
else
echo data/step$SEP$X
fi
else
echo $X
fi