123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- #!/bin/bash
- source libs/color_vars.sh
- declare -a desc_files
- declare -a todays_tasks
- function load_tasks
- {
- if [[ -n $(ls Tasks/) ]]; then
- desc_files=($(ls Tasks/*.description*))
- fi
- }
- function load_todays_tasks
- {
- if [[ -n $(ls Today/) ]]; then
- todays_tasks=($(ls Today/*.description*))
- fi
- }
- # Test if filename end in .done
- # Args: $1 = taskfile
- function is_done
- {
- if [[ "${1##*.}" == "done" ]]; then
- return 0
- else
- return 1
- fi
- }
- # Print task title
- # Args: $1 = taskfile
- function print_task_title
- {
- color_task $1
- head -n 1 "$1"
- echo -ne "$RESET_COLOR"
- }
- # Set colors on tasks that are done and active.
- # Args: $1 = filename
- function color_task
- {
- local ret
- if is_done $1; then
- echo -ne "$FG_GREEN$FG_BOLD"
- else
- echo -ne "$FG_CYAN"
- fi
- }
- # echo the filename of the logfile for a taskfile
- # Args: $1 = taskfile
- function get_logfile_name
- {
- if is_done $1; then
- echo -ne "${1%.description.done}.log"
- else
- echo -ne "${1%.description}.log"
- fi
- }
- # echo logfile date
- # Args: $1 = taskfile
- function print_logfile_date
- {
- stat -c %y "$(get_logfile_name $1)" | sed -n -e 's/\(.*\)\..*/\1/p'
- }
- function show_tasks
- {
- if [[ -v $desc_files ]]; then
- echo "No tasks."
- return 1
- fi
- local n_elements=${#desc_files[@]}
- for ((i=0; i < n_elements; i++)); do
- echo -ne "${FG_BOLD}[$i] "
- print_task_title ${desc_files[$i]};
- echo -ne "\t${FG_BOLD}Log Change: ${RESET_COLOR}"
- print_logfile_date ${desc_files[$i]}
- done
- return 0
- }
- function todays_tasks_show
- {
- if [[ -v $todays_tasks ]]; then
- echo "No tasks."
- return 1
- fi
- local n_elements=${#todays_tasks[@]}
- for ((i=0; i < n_elements; i++)); do
- echo -ne "${FG_BOLD}[$i] "
- print_task_title ${todays_tasks[$i]}
- echo -ne "\t${FG_BOLD}Log Change: ${RESET_COLOR}"
- local tasklog_file="Tasks/${todays_tasks[$i]##*/}"
- print_logfile_date $tasklog_file
- done
- return 0
- }
- function open_log
- {
- if [[ $1 == "-tasks" ]]; then
- load_tasks
- if(($2 < ${#desc_files[@]})); then
- nano "${desc_files[$2]%.description}.log"
- return 0
- fi
- else
- load_todays_tasks
- if(($1 < ${#todays_tasks[@]})); then
- local tasklog_file="${todays_tasks[$1]##*/}"
- nano "Tasks/${tasklog_file%.description}.log"
- return 0
- fi
- fi
- return 1
- }
- function show_description
- {
- if [[ $1 == "-today" ]]; then
- load_todays_tasks
- if(($2 < ${#todays_tasks[@]})); then
- echo -n "Log updated: "
- local tasklog_file="Tasks/${todays_tasks[$i]##*/}"
- print_logfile_date $tasklog_file
- echo ""
- tail -n +3 ${todays_tasks[$2]}
- return 0
- fi
- else
- load_tasks
- if(($1 < ${#desc_files[@]})); then
- echo -n "Log updated: "
- print_logfile_date ${desc_files[$1]}
- echo ""
- tail -n +3 ${desc_files[$1]}
- return 0
- fi
- fi
- return 1
- }
- # Works on today tasks
- # Input task number
- function task_done
- {
- task_file=${todays_tasks[$1]##*/}
- unlink Today/$task_file
- mv Tasks/$task_file Tasks/$task_file.done
- ln -r -s Tasks/$task_file.done Today/
- }
- function task_undone
- {
- task_file=${todays_tasks[$1]##*/}
- unlink Today/$task_file
- mv Tasks/$task_file Tasks/${task_file%.done}
- ln -r -s Tasks/${task_file%.done} Today/
- }
- function get_new_bottom_number
- {
- filenum=${#desc_files[@]}
- while((4 > ${#filenum})); do
- filenum="0${filenum}";
- done
- echo $filenum
- }
- # Low Priority
- # Add a new task through script instead of manual file creation
- # If we delete a file. The leading numbers and order will be fucked.
- function new_task
- {
- echo "New Task Title (only spaces, dots, alphabetical and numbers): "
- read task_title
- echo "New Task Description (end input with Ctrl+D): "
- task_description=$(cat)
- local num
- if [[ $desc_files != 0 ]]; then
- num=$(get_new_bottom_number)
- if((4 < ${#num})); then
- echo "Error: Too many tasks?"
- exit
- fi
- else
- num="0000"
- fi
- local filename=$(echo -ne "$task_title" | sed 's/ /_/g')
- filename=${filename,,}
- echo -e "$task_title" >> "Tasks/${num}-${filename}.description"
- echo -e "\n$task_description" >> "Tasks/${num}-${filename}.description"
- touch "Tasks/${num}-${filename}.log"
- }
- # High Priority
- # Makes the appropriate symlinking to the Today folder
- function take_task
- {
- ln -r -s "${desc_files[$1]}" Today/
- }
|