Page 2 of 2
Re: terminal todo list
Posted: Wed May 01, 2024 2:11 am
by geo_c
williwaw wrote: Tue Apr 30, 2024 11:57 pm
or
todoreplace7 for inside the file
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
Re: terminal todo list
Posted: Wed May 01, 2024 1:36 pm
by geo_c
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.
Re: terminal todo list
Posted: Wed May 01, 2024 5:51 pm
by Burunduk
geo_c wrote: Wed May 01, 2024 2:11 am
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
Once upon a time there was an editor named ed. It looks like you've just reinvented it.
Using the GNU ed:
Code: Select all
root# bat sMove
───────┬──────────────────────────────────────────────
│ File: sMove
───────┼──────────────────────────────────────────────
1 │ shelves
2 │ drumheads
3 │ drum parts/hardware
4 │ electronics
5 │ guitars
6 │ computer/board
───────┴──────────────────────────────────────────────
root# ed sMove
73
,n
1 shelves
2 drumheads
3 drum parts/hardware
4 electronics
5 guitars
6 computer/board
3i
sticks and mallets
.
,n
1 shelves
2 drumheads
3 sticks and mallets
4 drum parts/hardware
5 electronics
6 guitars
7 computer/board
wq
92
root# bat sMove
───────┬──────────────────────────────────────────────
│ File: sMove
───────┼──────────────────────────────────────────────
1 │ shelves
2 │ drumheads
3 │ sticks and mallets
4 │ drum parts/hardware
5 │ electronics
6 │ guitars
7 │ computer/board
───────┴──────────────────────────────────────────────
root#
While editing with ed is possible, the micro editor seems to be a bit more convenient.
Re: terminal todo list
Posted: Wed May 01, 2024 10:17 pm
by geo_c
Burunduk wrote: Wed May 01, 2024 5:51 pm
Once upon a time there was an editor named ed. It looks like you've just reinvented it.
Using the GNU ed:
Code: Select all
root# bat sMove
───────┬──────────────────────────────────────────────
│ File: sMove
───────┼──────────────────────────────────────────────
1 │ shelves
2 │ drumheads
3 │ drum parts/hardware
4 │ electronics
5 │ guitars
6 │ computer/board
───────┴──────────────────────────────────────────────
root# ed sMove
73
,n
1 shelves
2 drumheads
3 drum parts/hardware
4 electronics
5 guitars
6 computer/board
3i
sticks and mallets
.
,n
1 shelves
2 drumheads
3 sticks and mallets
4 drum parts/hardware
5 electronics
6 guitars
7 computer/board
wq
92
root# bat sMove
───────┬──────────────────────────────────────────────
│ File: sMove
───────┼──────────────────────────────────────────────
1 │ shelves
2 │ drumheads
3 │ sticks and mallets
4 │ drum parts/hardware
5 │ electronics
6 │ guitars
7 │ computer/board
───────┴──────────────────────────────────────────────
root#
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.