/
lit
executable file
·68 lines (68 loc) · 1.48 KB
/
lit
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
65
66
67
68
#!/usr/bin/env bash
set -eu
set -o pipefail
self=$(basename $0)
for arg in "$@"; do
if echo "$arg" | grep '=' >/dev/null 2>&1; then
arg_name=$(echo $arg | sed 's =.* ')
arg_value=$(echo $arg | sed 's ^[^=]*= ')
eval ${arg_name}='${arg_value}'
shift
else
break
fi
done
test -n "$lit"
tag=${tag-}
variant_in=${variant-default}
variant=$(echo ${variant-default} | sed 's | \\| g')
file=${file-}
if test -n "$file"; then
dir=$(dirname $file)
if test -z "$tag"; then
tag=$file
fi
if ! test -d "$dir"; then
mkdir -p $dir
fi
sed -n "s,^ ${tag}: ,,p;s,^ ${tag}:\(${variant}\): ,,p" $lit >$file
chmod +x $file
nocomment=${nocomment-false}
if ! $nocomment; then
case $file in
*.c|*.h)
echo "/* DO NOT EDIT THIS FILE. Auto-generated from $variant_in $lit by $self. */" >>$file
;;
*.hoon)
echo ":: DO NOT EDIT THIS FILE. Auto-generated from $variant_in $lit by $self." >>$file
;;
*.json)
;;
*)
echo "# DO NOT EDIT THIS FILE. Auto-generated from $variant_in $lit by $self." >>$file
;;
esac
fi
ext=$(echo $file | sed 's .*\. ')
fi
run=${run-}
if test -n "$run"; then
tag=${tag:-$(echo $run | sed 's,[ ].*$,,')}
ext=$tag
case $tag in
perl)
ext=pl
;;
python)
ext=py
;;
ruby)
ext=rb
;;
esac
sed -n "s,^ ${tag}: ,,p;s,^ ${tag}:\(${variant}\): ,,p" $lit >${lit}.${ext}
$run ${lit}.${ext} "$@"
fi
if test -z "$tag"; then
sed -n 's,^ \([^ ]\+\): .*,\1,p' $lit | sort | uniq
fi