todo.sh 596 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/sh
  2. #
  3. # Write/remove a task to do later.
  4. #
  5. # Select an existing entry to remove it from the file, or type a new entry to
  6. # add it.
  7. #
  8. file="$HOME/.todo.txt"
  9. touch "$file"
  10. height=$(wc -l "$file" | awk '{print $1}')
  11. prompt="Add/delete a task: "
  12. cmd=$(dmenu -l "$height" -p "$prompt" "$@" < "$file")
  13. while [ -n "$cmd" ]; do
  14. if grep -q "^$cmd\$" "$file"; then
  15. grep -v "^$cmd\$" "$file" > "$file.$$"
  16. mv "$file.$$" "$file"
  17. height=$(( height - 1 ))
  18. else
  19. echo "$cmd" >> "$file"
  20. height=$(( height + 1 ))
  21. fi
  22. cmd=$(dmenu -l "$height" -p "$prompt" "$@" < "$file")
  23. done
  24. exit 0