todo engine
This commit is contained in:
71
reporting/md-todo
Executable file
71
reporting/md-todo
Executable file
@@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
|
||||
function timecolor() {
|
||||
cat -
|
||||
}
|
||||
|
||||
function filelist() {
|
||||
shopt -s nullglob
|
||||
TODO=(*md)
|
||||
}
|
||||
|
||||
[[ "$1" = "-h" ]] && {
|
||||
echo '
|
||||
Maintain a set of TODOs in the current folder
|
||||
|
||||
'
|
||||
exit
|
||||
}
|
||||
|
||||
. qolop 2>/dev/null || {
|
||||
function _qCol() { true; }
|
||||
}
|
||||
VI=vimd
|
||||
which $VI &>/dev/null || VI=vim
|
||||
|
||||
while :;do
|
||||
filelist
|
||||
files=${#TODO[@]}
|
||||
{ _qCol G; printf '\n# List of TODOs: [unchecked/check boxes/lines]\n'; _qCol z; }
|
||||
i=0
|
||||
EDITFILE=""
|
||||
for ((n=0;n<files;n++)); do
|
||||
l="${TODO[$n]}"
|
||||
[[ -f "$l" ]] || continue
|
||||
i=$(( $n + 1 ))
|
||||
[[ -z $ANS ]] && {
|
||||
unchecked=$( grep -c '\[ \]' "$l" )
|
||||
checks=$( grep -c '\[.\]' "$l" )
|
||||
title=$( grep "^# " "$l" | head -n 1 )
|
||||
lines=$( sed '/^\s*$/d' "$l" | wc -l )
|
||||
_qCol y
|
||||
printf '%3s. %-20s [%d/%d/%d] %-20s\n' "$i" "$l" "$unchecked" "$checks" "$lines" "$title"
|
||||
}
|
||||
[[ "$ANS" -eq $i ]] && {
|
||||
EDITFILE="$l"
|
||||
break
|
||||
}
|
||||
done
|
||||
echo ""
|
||||
[[ -f "$EDITFILE" ]] && {
|
||||
$VI "$EDITFILE"
|
||||
ANS=""
|
||||
EDITFILE=""
|
||||
continue
|
||||
}
|
||||
{ _qCol W; printf '\n> (q)uit, (n)ew, ## to edit: '; _qCol z; }
|
||||
read -n ${#i} ANS
|
||||
ANS="${ANS//[^[:alnum:]]/}"
|
||||
echo ""
|
||||
[[ "$ANS" = "q" ]] && exit 0
|
||||
[[ "$ANS" = "x" ]] && exit 0
|
||||
[[ "$ANS" = "n" ]] && {
|
||||
ANS=""
|
||||
{ _qCol W; printf '\n> Name (.md will be added): '; _qCol z; }
|
||||
read NEWFILE
|
||||
[[ -z $NEWFILE ]] && { continue; }
|
||||
[[ -f "$NEWFILE".md ]] && { echo File already exists; continue; }
|
||||
echo "# $NEWFILE" > "$NEWFILE".md || { echo Cannot write file; continue; }
|
||||
}
|
||||
done
|
||||
:
|
||||
Reference in New Issue
Block a user