-
Notifications
You must be signed in to change notification settings - Fork 9
/
gtask-markdown
executable file
·55 lines (45 loc) · 1.15 KB
/
gtask-markdown
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
#!/usr/bin/bash
# this script will help converting the "gtask" output in a format that is printable in
# a markdown format so it'll be easier to be printed in the README.md file.
output=$(./gtask rc.color=off rc.defaultwidth=0 $@ 2>/dev/null | head -n -1)
positions=()
while read -r line; do
if [ "${line:0:1}" == "-" ]; then
# it's the Header Table
for (( i=0; i<${#line}; i++ )) do
ch="${line:$i:1}"
if [[ $ch == " " ]]; then
positions+=($i)
fi
done
break
fi
done < <(echo -e "$output")
echo -n "Last updated time: "
date -u; # print the date
echo
while IFS="|||" read -r line ; do
if [[ ${#line} == 0 ]]; then
echo
continue
fi
len=${positions[0]}
echo -ne "| ${line:0:$len} "
for (( i=0; i<${#positions[@]}; i++ )) do
pos=${positions[$i]}
next_pos=${positions[$(( i + 1 ))]}
if [[ $next_pos ]]; then
len=$(( next_pos - pos ))
else
line_count=${#line}
len=$(( line_count - pos ))
fi
pos=$(( pos + 1 ))
len=$(( len - 1 ))
if [[ $len -le 0 ]]; then
continue
fi
echo -n "| ${line:$pos:$len} "
done
echo "|"
done < <(echo -e "$output")