Okay, I've got a new function working: todoinsert [do/file]
works like this:
root# todoinsert sMove
Current text:
1:shelves
2:drumheads
3:drum parts/hardware
4:electronics
5:guitars
6:computer/board
Type line number to insert text: 3
Enter text to insert: sticks and mallets
Updated text:
1:shelves
2:drumheads
3:sticks and mallets
4:drum parts/hardware
5:electronics
6:guitars
7:computer/board
Here's the todoinsert.sh script:
Code: Select all
# 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