# mkdir -p ~/todo/do ~/todo/done
# add todo.sh to you .bashrc
# add this code to your .bashrc
# type 'todoinsert taskname' at the prompt to insert text to the specified line of a task file located in ../do
# https://sambrin.medium.com/fin-command-line-todo-list-made-with-30a2346de068
#STANDARD="\e[0m"
TODO_LIST_LABEL="\n----------Todo List-----------\n"
TODO_LIST_END="\n------------------------------\n"
COMP_LIST_LABEL="\n----------Done List-----------\n"
COMP_LIST_END="\n------------------------------\n"
TASKS_DIR=~/todo/do/
COMPLETED_DIR=~/todo/done/
function todoinsert {
if ! [[ -z "$1" ]] && [ -e ${TASKS_DIR}"${*}" ]
then
echo ""
printf "Current text:"
echo ""
grep -n "" ${TASKS_DIR}"${*}"
echo ""
read -p 'Type line number to insert text: ' LINENUM
read -p 'Enter text to insert: ' INSERTTEXT
echo ""
printf "Updated text:"
echo ""
sed -i "${LINENUM}i ${INSERTTEXT}" ${TASKS_DIR}"${*}"
grep -n "" ${TASKS_DIR}"${*}"
echo ""
else
# echo -e "\nusage: fin [existing task to complete]\n"
printf "${TODO_LIST_LABEL}"
find ${TASKS_DIR} -not -path '*/\.*' -type f -execdir echo '{}' ';' | nl -s ' ' -b n
printf "${TODO_LIST_END}"
fi
}
complete -o default -F _todoinsert todoinsert
I have one or two more functions to include in this set of scripts, and that would be a tododel function to remove specified lines from the /do text files. Maybe additional todo delete/insert functions to modify an existing line using a grep or sed. Being able to remove a range of lines or words rather than a single line or string might be nice also. But I think that might get complicated.
While editing with ed is possible, the micro editor seems to be a bit more convenient.
Yeah, I know, I go overboard sometimes. And I thought about using ed in the script, but the thing is, it's an editor and so you have to save and uses the character commands and all, whereas these todo scripts are about throwing info into a file quickly and doing a a couple quick edits on the fly, thereby creating files that can be opened in a full fledged editor if needed. I used micro to write these scripts. I like micro a lot.