NEW: Option to generate khal timetable
This commit is contained in:
parent
e020d85b0b
commit
b72efa23c2
|
@ -2,3 +2,4 @@ CURRENT_COURSE_DIR: $HOME/CurrentCourse
|
|||
ROOT_COURSE_DIR: $HOME/Documents/Studies
|
||||
|
||||
RELATIVE_INFO_FILE: info.yaml
|
||||
RELATIVE_TIMETABLE_FILE: timetable.yaml
|
||||
|
|
125
studyManager.sh
125
studyManager.sh
|
@ -154,6 +154,125 @@ sm_list_contents() {
|
|||
echo -n $selection | xclip -selection clipboard
|
||||
}
|
||||
|
||||
sm_timetable() {
|
||||
#
|
||||
# Use timetable to create task, events etc.
|
||||
#
|
||||
|
||||
sm_tt_usage() {
|
||||
local txt=(
|
||||
"Utility $APPNAME for managing your studies."
|
||||
"Usage: $APPNAME import [options]"
|
||||
""
|
||||
"Options:"
|
||||
" --help, -h Print help."
|
||||
)
|
||||
|
||||
printf "%s\n" "${txt[@]}"
|
||||
}
|
||||
|
||||
sm_tt_bad_usage() {
|
||||
local message="$1"
|
||||
local txt=(
|
||||
"For an overview of the command, execute:"
|
||||
"$APPNAME timetable --help"
|
||||
)
|
||||
|
||||
[[ $message ]] && printf "$message\n"
|
||||
|
||||
printf "%s\n" "${txt[@]}"
|
||||
}
|
||||
|
||||
sm_tt_khal() {
|
||||
local info_file="$CURRENT_COURSE_DIR/$RELATIVE_INFO_FILE"
|
||||
local timetable_file="$CURRENT_COURSE_DIR/$RELATIVE_TIMETABLE_FILE"
|
||||
|
||||
local start_date="2021-09-20"
|
||||
local end_date="2021-12-25"
|
||||
|
||||
sm_load_yaml_vars "${info_file}"
|
||||
sm_parse_yaml "${timetable_file}" timetable
|
||||
|
||||
for e in "${timetable[@]}"
|
||||
do
|
||||
|
||||
val=${e#*=}
|
||||
key=${e%%=*}
|
||||
|
||||
val="${val%\'}"
|
||||
val="${val#\'}"
|
||||
|
||||
val=($val)
|
||||
|
||||
local event_date=""
|
||||
|
||||
case "${val[0]}" in
|
||||
"Mon")
|
||||
event_date=$(date --date="${start_date} +0 days" +%d/%m/%Y)
|
||||
;;
|
||||
"Tue")
|
||||
event_date=$(date --date="${start_date} +1 days" +%d/%m/%Y)
|
||||
;;
|
||||
"Wed")
|
||||
event_date=$(date --date="${start_date} +2 days" +%d/%m/%Y)
|
||||
;;
|
||||
"Thu")
|
||||
event_date=$(date --date="${start_date} +3 days" +%d/%m/%Y)
|
||||
;;
|
||||
"Fri")
|
||||
event_date=$(date --date="${start_date} +4 days" +%d/%m/%Y)
|
||||
;;
|
||||
"Thu")
|
||||
event_date=$(date --date="${start_date} +5 days" +%d/%m/%Y)
|
||||
;;
|
||||
esac
|
||||
|
||||
command="khal new -a Timetable -r weekly -u $(date --date=${end_date} +%d/%m/%Y) -l ${val[3]//\\0040/' '} $event_date ${val[1]} ${val[2]} ${title} ${key}"
|
||||
|
||||
echo "$command"
|
||||
|
||||
read -p "Run above command [yn]? " -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]
|
||||
then
|
||||
eval "${command}"
|
||||
fi
|
||||
done
|
||||
exit 0
|
||||
}
|
||||
|
||||
sm_tt_task() {
|
||||
exit 0
|
||||
}
|
||||
|
||||
while (( $# ))
|
||||
do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
shift
|
||||
sm_tt_usage
|
||||
exit 0
|
||||
;;
|
||||
--khal|-k)
|
||||
shift
|
||||
sm_tt_khal
|
||||
exit 0
|
||||
;;
|
||||
--task|-t)
|
||||
shift
|
||||
sm_tt_task
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
sm_tt_bad_usage "Option/command not recognized."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
sm_tt_bad_usage
|
||||
exit 1
|
||||
}
|
||||
|
||||
while (( $# ))
|
||||
do
|
||||
case $1 in
|
||||
|
@ -172,6 +291,12 @@ do
|
|||
exit 0
|
||||
shift
|
||||
;;
|
||||
timetable)
|
||||
command=$1
|
||||
shift
|
||||
sm_"$command" "$@"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
sm_bad_usage "Option/command not recognized."
|
||||
exit 1
|
||||
|
|
Loading…
Reference in New Issue