csot/contest

Task 12 (Bonus) — todo CLI in pure bash

A tiny todo manager with add, list, done, and remove. State is stored in a flat text file.

Submit as

12-todo/todo.sh (must live inside a 12-todo/ directory)

Input

Invocation

./12-todo/todo.sh <subcommand> [args...]
Subcommand Arguments Meaning
add <text…> Append a new open item (one line of text; spaces allowed)
list (none) Print all items
(none) Same as list if invoked with no subcommand
done <n> Mark line n complete ([ ][x])
remove <n> Delete line n
anything else Invalid

<n> is a 1-based line number (first line = 1).

State file

Source Format
Env TODO_FILE — if set, use this path for storage
Default $HOME/.todo
File contents One todo per line. Open: [ ] <text>. Done: [x] <text> (after done).

Output

Subcommand stdout stderr Exit
add <text> Not checked (usually empty) Not checked 0
list / no args Numbered lines: <n>: [ ] text or <n>: [x] text Not checked 0
done <n> Not checked Not checked 0
remove <n> Not checked Not checked 0
invalid Not checked Usage message 2

list line format

<n>: [ ] <text>    # open item
<n>: [x] <text>    # completed item

<n> matches the current 1-based line number in the file after any prior edits.

Example session

export TODO_FILE=/tmp/my-todo
./12-todo/todo.sh add "buy milk"
./12-todo/todo.sh add "write code"
./12-todo/todo.sh add "sleep"
./12-todo/todo.sh list

stdout:

1: [ ] buy milk
2: [ ] write code
3: [ ] sleep
./12-todo/todo.sh done 2
./12-todo/todo.sh list

stdout:

1: [ ] buy milk
2: [x] write code
3: [ ] sleep
./12-todo/todo.sh remove 1
./12-todo/todo.sh list

stdout:

1: [x] write code
2: [ ] sleep

(Line numbers renumber in list output after a remove.)

What the grader checks

The grader runs your script in a fresh temp dir with HOME and TODO_FILE set.

Visible checks (5 pts)

Through done 2 in the example session above (not remove). On failure you see expected vs got:

Step Points
add × three items 1
list after adds 2
done 2 then list 2

Hidden checks (5 pts)

Not spelled out in the example. Pass/fail only — includes remove, invalid commands, and bare-invocation behavior.

Hints

  • echo "[ ] $text" >> "$file"
  • sed -i '${n}s/^\[ \]/[x]/' for done
  • sed -i '${n}d' for remove
  • awk '{ printf "%d: %s\n", NR, $0 }' for list

Points: 10 (capstone — partial grading)

Kind Points
Visible (through done 2) 5
Hidden (remove + edge cases) 5

Each visible step is graded independently with expected-vs-got feedback on failure.

Other tasks