Guest User

Untitled

a guest
Oct 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. ### --------
  4. ### BASH Todo v.01
  5. ### A Super Simple Todo CLI
  6. ### Created by: Lazy
  7. ### --------
  8.  
  9. ######################################################################
  10. ####################### INSTALLATION AND USAGE #######################
  11. #
  12. #
  13. # Place todo.sh in your PATH so you can easily run it. Make sure you
  14. # set permissions to write and read.
  15. # You can easily add a task with:
  16. # todo -a "Task goes here"
  17. # You can easily view tasks with:
  18. # todo -l simple (shows a numbered list)
  19. # todo -l full (shows when task is created)
  20. #
  21.  
  22.  
  23. ## Changelog
  24. # -TODOFORMAT removed. Task numberer finished. (For some reason the function
  25. # doesn't manipulate TODO file (WHY?) )
  26.  
  27.  
  28. # Text color variables
  29. # to be implemented with Priority colors
  30. txtund=$(tput sgr 0 1) # Underline
  31. txtbld=$(tput bold) # Bold
  32. txtred=$(tput setaf 1) # Red
  33. txtgrn=$(tput setaf 2) # Green
  34. txtylw=$(tput setaf 3) # Yellow
  35. txtblu=$(tput setaf 4) # Blue
  36. txtpur=$(tput setaf 5) # Purple
  37. txtcyn=$(tput setaf 6) # Cyan
  38. txtwht=$(tput setaf 7) # White
  39. txtrst=$(tput sgr0) # Text reset
  40.  
  41.  
  42. TODORM () {
  43. TASKNUM=`awk -F: '{ print $1 }' ~/TODO | grep -w $OPTARG`
  44. if [[ "$OPTARG" = "$TASKNUM" ]]; then
  45. grep -wv "^[${OPTARG}]" TODO > NEWTODO
  46. cp NEWTODO TODO
  47. else
  48. echo "Error: Task $OPTARG does not exist"
  49. fi
  50. }
  51.  
  52.  
  53. TODOLIST () {
  54. #awk -F:'{print $1,$4}'
  55. # : delimiter for awk
  56. # | for column
  57. if [[ -a /home/$USER/TODO ]]; then
  58.  
  59. case $OPTARG in
  60. full)
  61. column -t -s "|" ~/TODO | awk -F: 'BEGIN { print " Created On To-do"
  62. print "================ =====================" }
  63. { print $2," ",$3}'
  64. ;;
  65. simple)
  66. column -t -s "|" ~/TODO | awk -F: '{ print "\033[1;31m" $1"." "\033[0m",$3 }'
  67. ;;
  68. esac
  69. else
  70. echo TODO file does not exist. Create a new task first.
  71. fi
  72. }
  73.  
  74. ### END DEFINING FUNCTIONS ####
  75.  
  76. while getopts "a:l:m:h" OPTION
  77. do
  78. case $OPTION in
  79. h)
  80. echo "OPTIONS:"
  81. echo " todo -a "[\"Task goes here\"]" "
  82. echo " todo -l [OPTION]"
  83. echo " simple -- shows a numbered list "
  84. echo " full -- shows a full list with creation date"
  85. echo " todo -m "[Task number]" "
  86. echo " To clear out tasklist simply delete the TODO file in your /home/$USER/"
  87. ;;
  88. a)
  89. touch /home/$USER/TODO
  90. date=`date +"%Y-%m-%d"`
  91. TEST=`awk -F: '{ print $1 }' ~/TODO | tail -n 1`
  92. declare -i TEST
  93. number=0
  94. if [[ $number = $TEST ]] ; then
  95. echo "$number:|$date:|$OPTARG:|$PRI:|" >> /home/$USER/TODO
  96. else
  97. let "TEST += 1"
  98. PRI=$3
  99. echo "$TEST:|$date:|$OPTARG:|$PRI:|" >> /home/$USER/TODO
  100. fi
  101. ;;
  102. l)
  103. TODOLIST
  104. ;;
  105. m)
  106. TODORM
  107. exit 0 ;;
  108. esac
  109. done
Add Comment
Please, Sign In to add comment