diff --git a/tasks.sh b/tasks.sh index 0840b86..dec2773 100755 --- a/tasks.sh +++ b/tasks.sh @@ -12,6 +12,27 @@ command=$1 getopts "t" typora; #check if -t flag is given +function listTasks() { + files=( $tasks_dir/*.md ) + index=0 + echo "ACTIVE TASKS: " + for file in "${files[@]##*/}"; do + ((index++)) + echo "$index) $file" + done +} + +function listProjects() { + cd "$tasks_dir" + dirs=( */ ) + index=0 + echo "PROJECTS: " + for dir in "${dirs[@]}"; do + ((index++)) + echo "${index}) ${dir}" + done +} + function editFile() { notesSync @@ -58,14 +79,9 @@ function createtask() { ## LIST tasks in directory if [ "$1" = "list" ] || [ "$1" = "l" ]; then - echo "ACTIVE TASKS: " notesSync - files=( $tasks_dir/*.md ) - index=0 - for file in "${files[@]##*/}"; do - ((index++)) - echo "$index) $file" - done + listTasks + listProjects ## OPEN a task from a list elif [ "$1" = "open" ] || [ "$1" = "o" ]; then @@ -173,18 +189,51 @@ elif [ "$1" = "copy" ] || [ "$1" = "c" ]; then done fi -## CREATE PROJECT +## Move a task to a project +elif [ "$1" = "move" ] || [ "$1" = "m" ]; then + notesSync + files=( $tasks_dir/*.md ) + if ! [ "$2" = "" ]; then + index=($2-1) + move_file=${files[$index]} + editFile "$move_file" + else + PS3="Move file #: " + echo "Please select a file to MOVE." + select file in "${files[@]##*/}"; do + { + echo "Moving $file" + PS3="Select Project: " + echo "Select a project" + cd $tasks_dir + dirs=( */ ) + # Select a project to move the item to + select directory in "${dirs[@]}"; do + { + mv "${tasks_dir}/${file}" "${tasks_dir}/${directory}" + break + } || { + echo "bad choice" + break + } + done + + break + } || + { + echo "bad choice" + break + } + done + fi + +## CREATE a project elif [ "$1" = "project" ] || [ "$1" = "j" ]; then read -p "Create new project: " project mkdir "$tasks_dir/$project" ## CREATE a task (default) else - index=0 - for dir in "$(cd $tasks_dir && ls -d -- */)"; do - ((index++)) - echo "$index) $dir" - done createtask fi