feat(tasks): update features of task management"
This commit is contained in:
parent
86afd4ff11
commit
60fdb30640
2 changed files with 228 additions and 51 deletions
85
tasks.sh
85
tasks.sh
|
@ -15,18 +15,17 @@ getopts "t" typora; #check if -t flag is given
|
||||||
function editFile() {
|
function editFile() {
|
||||||
notesSync
|
notesSync
|
||||||
|
|
||||||
edit_file="${tasks_dir}/$1"
|
|
||||||
# Open in editor
|
# Open in editor
|
||||||
if [ "$typora" = "t" ]; then
|
if [ "$typora" = "t" ]; then
|
||||||
typora "$edit_file"
|
typora "$1"
|
||||||
else
|
else
|
||||||
vim "$edit_file"
|
vim "$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
notesSync
|
notesSync
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTask() {
|
function createtask() {
|
||||||
{
|
{
|
||||||
read -p "Create new task: " title
|
read -p "Create new task: " title
|
||||||
|
|
||||||
|
@ -40,17 +39,18 @@ function createTask() {
|
||||||
|
|
||||||
# IF Not Exists: create file & echo date
|
# IF Not Exists: create file & echo date
|
||||||
if ! test -f "$full_path"; then
|
if ! test -f "$full_path"; then
|
||||||
install -Dv /dev/null "$full_path"
|
install -Dv /dev/null "$full_path" >/dev/null
|
||||||
# TODO: update to correct heading from old entries
|
# TODO: update to correct heading from old entries
|
||||||
heading="# $title"
|
heading="# $title"
|
||||||
echo $heading > "$full_path"
|
echo $heading > "$full_path"
|
||||||
date_heading=$(date +'%b %d, %Y, %a %r')
|
date_heading=$(date +'%b %d, %Y, %a %r')
|
||||||
echo $date_heading >> "$full_path"
|
echo $date_heading >> "$full_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
editFile "$full_path"
|
editFile "$full_path"
|
||||||
|
|
||||||
} || {
|
} || {
|
||||||
echo ">>> New note failed"
|
echo ">>> New task failed"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,14 +65,22 @@ if [ "$1" = "list" ] || [ "$1" = "l" ]; then
|
||||||
echo "$index) $file"
|
echo "$index) $file"
|
||||||
done
|
done
|
||||||
|
|
||||||
## OPEN a note from a list
|
## OPEN a task from a list
|
||||||
elif [ "$1" = "open" ] || [ "$1" = "o" ]; then
|
elif [ "$1" = "open" ] || [ "$1" = "o" ]; then
|
||||||
files=( $tasks_dir/*.md )
|
files=( $tasks_dir/*.md )
|
||||||
|
|
||||||
|
if ! [ "$2" = "" ]; then
|
||||||
|
index=($2-1)
|
||||||
|
open_file=${files[$index]}
|
||||||
|
editFile "$open_file"
|
||||||
|
notesSync
|
||||||
|
else
|
||||||
PS3="Open file #: "
|
PS3="Open file #: "
|
||||||
echo "Please select a file to OPEN."
|
echo "Please select a file to OPEN."
|
||||||
notesSync
|
notesSync
|
||||||
select file in "${files[@]##*/}"; do
|
select file in "${files[@]##*/}"; do
|
||||||
{
|
{
|
||||||
|
echo "Opening $file"
|
||||||
editFile "$file"
|
editFile "$file"
|
||||||
break
|
break
|
||||||
} ||
|
} ||
|
||||||
|
@ -81,16 +89,24 @@ elif [ "$1" = "open" ] || [ "$1" = "o" ]; then
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
## MARK AS DONE a note from a list
|
## MARK AS DONE a task from a list
|
||||||
elif [ "$1" = "done" ] || [ "$1" = "d" ]; then
|
elif [ "$1" = "done" ] || [ "$1" = "d" ]; then
|
||||||
files=( $tasks_dir/*.md )
|
files=( $tasks_dir/*.md )
|
||||||
PS3="Mark as Done, file #: "
|
|
||||||
echo "Mark a task as DONE ($(ls ${notes_dir}/tasks/done | wc -l))."
|
|
||||||
notesSync
|
notesSync
|
||||||
|
|
||||||
|
if ! [ "$2" = "" ]; then
|
||||||
|
index=($2-1)
|
||||||
|
done_file=${files[$index]}
|
||||||
|
mv "$done_file" "${tasks_dir}/done/"
|
||||||
|
notesSync
|
||||||
|
else
|
||||||
|
PS3="Mark as Done, file #: "
|
||||||
|
echo "Mark a task as DONE ($(ls ${tasks_dir}/done/ | wc -l))."
|
||||||
select file in "${files[@]##*/}"; do
|
select file in "${files[@]##*/}"; do
|
||||||
{
|
{
|
||||||
mv "${tasks_dir}/${file}" "${tasks_dir}/done"
|
mv "${tasks_dir}/${file}" "${tasks_dir}/done/"
|
||||||
notesSync
|
notesSync
|
||||||
break
|
break
|
||||||
} ||
|
} ||
|
||||||
|
@ -99,14 +115,22 @@ elif [ "$1" = "done" ] || [ "$1" = "d" ]; then
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
## REMOVE a task from a list
|
||||||
## REMOVE a note from a list
|
|
||||||
elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then
|
elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then
|
||||||
files=( $tasks_dir/*.md )
|
files=( $tasks_dir/*.md )
|
||||||
PS3="Remove file #: "
|
|
||||||
echo "Please select a file to REMOVE."
|
|
||||||
notesSync
|
notesSync
|
||||||
|
|
||||||
|
if ! [ "$2" = "" ]; then
|
||||||
|
index=($2-1)
|
||||||
|
remove_file=${files[$index]}
|
||||||
|
echo "Removing $remove_file"
|
||||||
|
rm "$remove_file"
|
||||||
|
notesSync
|
||||||
|
else
|
||||||
|
PS3="Remove task #: "
|
||||||
|
echo "Select a task to DELETE."
|
||||||
select file in "${files[@]##*/}"; do
|
select file in "${files[@]##*/}"; do
|
||||||
{
|
{
|
||||||
echo "Removing $file"
|
echo "Removing $file"
|
||||||
|
@ -119,8 +143,35 @@ elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
## CREATE a note (default)
|
## COPY content a task from a list
|
||||||
|
elif [ "$1" = "copy" ] || [ "$1" = "c" ]; then
|
||||||
|
files=( $tasks_dir/*.md )
|
||||||
|
|
||||||
|
if ! [ "$2" = "" ]; then
|
||||||
|
index=($2-1)
|
||||||
|
copy_file=${files[$index]}
|
||||||
|
echo "Copied content of $copy_file"
|
||||||
|
xclip -sel c < "$copy_file"
|
||||||
|
else
|
||||||
|
PS3="Copy file content #: "
|
||||||
|
echo "Select a task to COPY Content."
|
||||||
|
select file in "${files[@]##*/}"; do
|
||||||
|
{
|
||||||
|
echo "Copied content of $file"
|
||||||
|
xclip -sel c < "${tasks_dir}/${file}"
|
||||||
|
break
|
||||||
|
} ||
|
||||||
|
{
|
||||||
|
echo "bad choice"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
## CREATE a task (default)
|
||||||
else
|
else
|
||||||
createTask
|
createtask
|
||||||
fi
|
fi
|
||||||
|
|
126
tasks.sh.bkup
Executable file
126
tasks.sh.bkup
Executable file
|
@ -0,0 +1,126 @@
|
||||||
|
#! /usr/bin/bash
|
||||||
|
|
||||||
|
## tasks management
|
||||||
|
|
||||||
|
# Load config
|
||||||
|
. ${HOME}/ayo.conf
|
||||||
|
. ${scripts_dir}/functions.sh
|
||||||
|
|
||||||
|
# TODO: write log for echoes with >>>
|
||||||
|
|
||||||
|
command=$1
|
||||||
|
|
||||||
|
getopts "t" typora; #check if -t flag is given
|
||||||
|
|
||||||
|
function editFile() {
|
||||||
|
notesSync
|
||||||
|
|
||||||
|
edit_file="${tasks_dir}/$1"
|
||||||
|
# Open in editor
|
||||||
|
if [ "$typora" = "t" ]; then
|
||||||
|
typora "$edit_file"
|
||||||
|
else
|
||||||
|
vim "$edit_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
notesSync
|
||||||
|
}
|
||||||
|
|
||||||
|
function createTask() {
|
||||||
|
{
|
||||||
|
read -p "Create new task: " title
|
||||||
|
|
||||||
|
if [ "$title" = "" ]; then
|
||||||
|
echo "Title cannot be empty."
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
file_name=$title.md
|
||||||
|
full_path="${tasks_dir}/${file_name}"
|
||||||
|
|
||||||
|
# IF Not Exists: create file & echo date
|
||||||
|
if ! test -f "$full_path"; then
|
||||||
|
install -Dv /dev/null "$full_path"
|
||||||
|
# TODO: update to correct heading from old entries
|
||||||
|
heading="# $title"
|
||||||
|
echo $heading > "$full_path"
|
||||||
|
date_heading=$(date +'%b %d, %Y, %a %r')
|
||||||
|
echo $date_heading >> "$full_path"
|
||||||
|
fi
|
||||||
|
editFile "$full_path"
|
||||||
|
|
||||||
|
} || {
|
||||||
|
echo ">>> New note failed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
## LIST tasks in directory
|
||||||
|
if [ "$1" = "list" ] || [ "$1" = "l" ]; then
|
||||||
|
files=( $tasks_dir/*.md )
|
||||||
|
index=0
|
||||||
|
notesSync
|
||||||
|
for file in "${files[@]##*/}"; do
|
||||||
|
((index++))
|
||||||
|
echo "$index) $file"
|
||||||
|
done
|
||||||
|
|
||||||
|
## OPEN a note from a list
|
||||||
|
elif [ "$1" = "open" ] || [ "$1" = "o" ]; then
|
||||||
|
files=( $tasks_dir/*.md )
|
||||||
|
PS3="Open file #: "
|
||||||
|
echo "Please select a file to OPEN."
|
||||||
|
notesSync
|
||||||
|
select file in "${files[@]##*/}"; do
|
||||||
|
{
|
||||||
|
editFile "$file"
|
||||||
|
break
|
||||||
|
} ||
|
||||||
|
{
|
||||||
|
echo "bad choice"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
|
## MARK AS DONE a note from a list
|
||||||
|
elif [ "$1" = "done" ] || [ "$1" = "d" ]; then
|
||||||
|
files=( $tasks_dir/*.md )
|
||||||
|
PS3="Mark as Done, file #: "
|
||||||
|
echo "Mark a task as DONE ($(ls ${notes_dir}/tasks/done | wc -l))."
|
||||||
|
notesSync
|
||||||
|
select file in "${files[@]##*/}"; do
|
||||||
|
{
|
||||||
|
mv "${tasks_dir}/${file}" "${tasks_dir}/done"
|
||||||
|
notesSync
|
||||||
|
break
|
||||||
|
} ||
|
||||||
|
{
|
||||||
|
echo "bad choice"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
## REMOVE a note from a list
|
||||||
|
elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then
|
||||||
|
files=( $tasks_dir/*.md )
|
||||||
|
PS3="Remove file #: "
|
||||||
|
echo "Please select a file to REMOVE."
|
||||||
|
notesSync
|
||||||
|
select file in "${files[@]##*/}"; do
|
||||||
|
{
|
||||||
|
echo "Removing $file"
|
||||||
|
rm "${tasks_dir}/${file}"
|
||||||
|
notesSync
|
||||||
|
break
|
||||||
|
} ||
|
||||||
|
{
|
||||||
|
echo "bad choice"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
|
## CREATE a note (default)
|
||||||
|
else
|
||||||
|
createTask
|
||||||
|
fi
|
Loading…
Reference in a new issue