-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmtl-funcs
executable file
·43 lines (37 loc) · 992 Bytes
/
mtl-funcs
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
#!/bin/bash
getdocname(){
echo "$1~" | cut -d "~" -f 1
}
getrev(){
let "FIELD=$2 + 1"
echo "$1~" | cut -d "~" -f ${FIELD}
}
getdoc(){
echo $(getdocname $(resolvedoc $1) )
}
resolvedoc(){
DOC=$(getdocname $1)
REV1=$(getrev $1 1)
REV2=$(getrev $1 2)
if [ "$DOC" == ":today" ]; then
DOC=`date --rfc-3339=date`
elif [ "$DOC" == ":yesterday" ] || [ "$1" == ":yday" ]; then
DOC=`date --rfc-3339=date -d yesterday`
elif [ "$DOC" == ":tomorrow" ]; then
DOC=`date --rfc-3339=date -d tomorrow`
fi
echo "$DOC~$REV1~$REV2"
}
getblob(){
LINE=1
DOC=$(getdocname $1) #`echo "$1~" | cut -d"~" -f1`
REV=$(getrev $1 $2) #`echo "$1~" | cut -d"~" -f${FIELD}`
if [[ $REV == "" ]] || [[ $REV =~ [0-9] ]]; then
if [ -f .mtl/${DOC}.index ]; then
let "LINE= $REV + 1"
tail -n $LINE .mtl/${DOC}.index | head -n 1 | awk '{ print $1 }'
fi
elif [[ $REV == "w" ]]; then
echo "../${DOC}"
fi
}