72 lines
1.7 KiB
Bash
Executable File
72 lines
1.7 KiB
Bash
Executable File
#!/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 [%02d/%02d/%02d] %-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
|
|
:
|