-
Notifications
You must be signed in to change notification settings - Fork 4
/
makeindex.sh
executable file
·79 lines (64 loc) · 1.16 KB
/
makeindex.sh
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
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
upvar() {
if unset -v "$1"; then # Unset & validate varname
if (( $# == 2 )); then
eval $1=\"\$2\" # Return single value
else
eval $1=\(\"\${@:2}\"\) # Return array
fi
fi
}
function io.readln
{
read -r
}
function io.writeln
{
echo "$*" >> index.html
}
# {{{
function basename
{
local __rv="${1##*/}"
local "$3" && upvar $3 "$__rv"
}
function dirname
{
local __rv="${1%/*}"
local "$3" && upvar $3 "$__rv"
}
function extension
{
local __rv="${1##*.}"
local "$3" && upvar $3 "$__rv"
}
function noextension
{
local __rv="${1%.*}"
local "$3" && upvar $3 "$__rv"
}
function is_jpeg_ext
{
local __rv=1
shopt -s nocasematch
[[ $1 == jpg ]] && __rv=0
shopt -u nocasematch
return $__rv
}
# }}}
function main
{
find . -type d -maxdepth 1 |
while io.readln
do
echo "Processing: '$REPLY'..."
fn="${REPLY}"
dirname "$fn" into dn
basename "$fn" into bn
extension "$bn" into ext
noextension "$bn" into noext
[[ $bn == "." ]] && continue
io.writeln '<div class="directory line"><div class="name"><a href="'"$bn"'/">'"$bn"'</a></div></div>'
done
}
main "$@"