Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # TO-DO list manager that'll remind you taks to be done; if any task has failed
- # to remind, it will be reported.
- #
- # !!! As the script uses cron, it is advised to install current cron jobs
- # into systemwide corntab (e.g. into '/etc/cron.d/' directory or
- # '/etc/crontab' file). Otherwise currently installed cron jobs will be overwritten !!!
- #
- # Requires notify-send and zenity to be installed.
- #
- # -h or --help for more info.
- #
- # Don't forget to make this file executable!
- #
- # Last update 17. Mar 2013
- # TO DO: - add possibility to add tasks without reminder;
- # hetkel lahendatav 'add' flagiga - st croni ei kanta, kuid db-sse läheb;
- # jääb veel auto-checki vältimise küss.
- #
- # - instead of default +week reminder of i-marked birthday,
- # ask user how many days before bd would reminder have to pop up
- #
- # Written by Laur Aliste [ laur.aliste ät gmail ]
- ############################### EDITABLE ITEMS ###############################
- todo_database="/data/Documents/.todo.dat" # Location and name of the todo database.
- birthday_database="/data/Documents/.birthdays.dat" # Location and name of the birthday database.
- cron="/data/Documents/.cron.dat" # Location and name of the cron file.
- max_size="1" # Max allowed size of to-do and birthday databases (in MB). Simply a precautionary feature.
- install_path="/usr/local/bin" # Where script will be installed by install_ function
- ##############################################################################
- # If you ain't sure what your're doing, don't edit anything below this line.
- ##############################################################################
- # Tags that are part of task/birthday database entry ID field:
- tag1="!#" # DO NOT use single quotes(') in tags!
- tag2="#!"
- zero=${0##*/} # (same as running `basename $0`)
- DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Location of this scriptfile.
- disp=":0.0"
- disp2="$DISPLAY"
- export DISPLAY=:0.0
- bold="tput smso"
- offbold="tput rmso"
- unset add important skip repetitive UI another_date date_arr skip_confirm monthtag daytag
- current_year=$(date +%Y)
- NOW=$((`date +%s`))
- tmp="/tmp/.todo_script_tmpfile_089123.tmp"
- todo_cron_dir="/etc/cron.d"
- todo_crontab="$todo_cron_dir/todo_script_crontab"
- ############################## DEFINE FUNCTIONS ##############################
- function check_files() {
- # Will check whether required files are existing; if not, will create
- # or ask whether to create:
- for i in $@; do
- if [ -f $i ]; then
- continue
- elif [[ "$i" == "$todo_database" ]]; then
- echo $(crontab -l) > $tmp
- if [[ -n "$(crontab -l)" ]] || [[ -z "$(grep 'no crontab for' $tmp)" ]]; then
- zenity --question --text="!!! IMPORTANT !!!\n\nIt seems you're running this script for the first time.\nYou also have some cronjobs installed in crontab.\nMake sure you back up those cron-jobs found in crontab.\n(they can be viewed by running 'crontab -l');\nif you proceed, those entries WILL be overwritten!\n\nSee '$zero -h' for more info.\n\nContinue?" || exit 1
- else
- zenity --question --text="!!! IMPORTANT !!!\n\nIt seems you're running this script for the first time.\nYou currently have no cron-jobs installed in crontab,\nbut notice that simple crontab can no loger be used, since this script overwrites it;\nyou'll be better off using '/etc/cron.d/' or similar.\n\nSee '$zero -h' for more info.\n\nContinue?" || exit 1
- fi
- > $i
- else
- > $i
- fi
- done
- }
- function check_program() {
- # Will check whether necessary programs are installed; if not, exit:
- for i in $@; do
- if ! command -v $i >/dev/null; then
- printf "ERROR\n$i does not appear to be installed on your system.\nsudo apt-get install $i\n" >&2; exit 1
- fi
- done
- }
- function generate_ident() {
- # Creates unique ID for name in birthday database or task in todo database.
- ident="$tag1$RANDOM$tag2"
- # Make sure this ident isn't already existing in corresponding database:
- until [[ -z "$(grep $ident $1)" ]]; do
- ident="$tag1$RANDOM$tag2"
- done
- }
- function check_filesize() {
- # Check if file is larger than predefined size; simply a precautionary feature:
- for i in $@; do
- size=$(du -LshBM $i | cut -f1) #Prints dir size in megs; note the -L option follows symbolic links
- if [[ "${size:0:$(( ${#size} - 1 ))}" -gt "$max_size" ]]; then
- #if [[ "$(( $(stat --printf="%s" $i) / 1000000 ))" -gt "$max_size" ]]; then
- notify-send -t 0 -i gtk-dialog-error "$i is more than $max_size MB in size! Aborting."; exit 1
- fi
- done
- }
- function print_error() {
- # Different kind of errors to display:
- clear
- case $1 in
- "wrong_format")
- notify-send -t 0 -i gtk-dialog-error "$zero script could not identify the date format for the repetitive task
- \"$2\":
- ( $3 ) Aborting."; exit 1
- ;;
- #-----------------------------------------------------------------------------
- "wrong_format_date")
- notify-send -t 0 -i gtk-dialog-error "$zero script could not identify the date format for the repetitive task
- \"$2\":
- ( $3 ) Aborting.
- (one of the probable reason could be writing date as 'D' instead of '0D', e.g.
- Dec 1 should be entered as Dec 01)"; exit 1
- ;;
- #-----------------------------------------------------------------------------
- "bad_date")
- echo "========================================================================"
- echo " Error: please re-check the date entry ($2)"
- echo -e " for task\n\n\"$3\"\n\n Looks like it contains ill-logical values."
- echo "========================================================================"; exit 1
- ;;
- #-----------------------------------------------------------------------------
- "few_args")
- echo "========================================================================="
- echo " Error: exactly one argument (the number of task to be deleted) required!"
- echo "========================================================================="; exit 1
- ;;
- esac
- }
- function find_time_details() {
- # Create different time-values (e.g. hours, minutes, day, date, year...):
- mins=$(eval date +%M -d \"$@\") > /dev/null 2>&1
- hours=$(eval date +%H -d \"$@\") > /dev/null 2>&1
- hrs_mins=$(eval date +%R -d \"$@\") > /dev/null 2>&1
- date=$(eval date +%d -d \"$@\") > /dev/null 2>&1
- day=$(eval date +%a -d \"$@\") > /dev/null 2>&1
- month=$(eval date +%m -d \"$@\") > /dev/null 2>&1
- month_char=$(eval date +%b -d \"$@\") > /dev/null 2>&1
- year=$(eval date +%Y -d \"$@\") > /dev/null 2>&1
- datetime=$(eval date -d \"$@\") > /dev/null 2>&1
- month_cap=$(eval date +%^b -d \"$@\") > /dev/null 2>&1 # For comparison purposes
- day_cap=$(eval date +%^a -d \"$@\") > /dev/null 2>&1 # For comparison purposes
- TARGET=$(eval date +%s -d \"$@\") > /dev/null 2>&1
- }
- function build_repetitive_dateline() {
- # Builds a repetitive task execution date for todo-database:
- # Note the find_time_details should have already been called by now!
- time="$@"
- if [[ "$UI" != "True" ]]; then # in case of GUI usage, $gap and $time are already defined within add_task function
- time_cap="$(echo $time | tr '[:lower:]' '[:upper:]')" # For comparing strings below
- # Try to figure out which variables were passed as dates:
- if [[ "$monthtag" == "True" ]]; then
- time="$month_char $date $hrs_mins"
- gap="month"
- elif [[ "$daytag" == "True" ]]; then
- time="$hrs_mins"
- gap="day"
- elif [[ "$#" == "1" ]]; then
- if [[ "$1" == $hrs_mins ]]; then
- time="$hrs_mins"
- gap="day"
- elif [[ "$time_cap" == *$day_cap* ]]; then
- time="$day $hrs_mins"
- gap="next week"
- else
- print_error "wrong_format" "$task" "$time"
- fi
- elif [[ "$#" == "2" ]]; then
- if [[ "$time_cap" == *$day_cap* ]] && [[ "$time_cap" == *$hrs_mins* ]]; then
- time="$day $hrs_mins"
- gap="next week"
- elif [[ "$time_cap" == *$month_cap* ]] && [[ "$time_cap" == *$date* ]]; then
- time="$month_char $date"
- gap="next year"
- else
- print_error "wrong_format_date" "$task" "$time"
- fi
- elif [[ "$#" == "3" ]]; then
- if [[ "$time_cap" == *$month_cap* ]] && [[ "$time_cap" == *$date* ]] && \
- [[ "$time_cap" == *$hrs_mins* ]]; then
- time="$month_char $date $hrs_mins"
- gap="next year"
- else
- print_error "wrong_format_date" "$task" "$time"
- fi
- else
- print_error "wrong_format" "$task" "$time"
- fi
- fi
- # Build first exec time:
- exe_time="$(eval date -d \"$time\")"
- # If the target date is already history, add +gap for the exec time
- if [[ "$((`date +%s -d "$exe_time"`))" -lt "$((`date +%s`))" ]]; then
- exe_time="$(eval date -d \"$time+$gap\")"
- fi
- # Finally, build the entry2, that'll be echoed into DB after ID
- entry2="\"$time\" \"$exe_time\" \"$gap\""
- }
- function check_time () {
- # Checks whether task to be added is valid, in the past or far in the future;
- # also used by automatic checker to inform user if any task has failed to execute.
- time="$@"
- if [[ "$auto_check" == "True" ]]; then
- if [[ "$TARGET" -lt "$NOW" ]]; then # Meaning task has failed to execute
- skip="True"
- if [[ "$repetitive" == "True" ]]; then
- if zenity --question --cancel-label="Nope, leave it be" --ok-label="OK" --text="It looks like repetitive task\n\n\"$task\"\n\nhas failed to remind.\n(execution time should have been at $time)\n\nPress OK to update reminder date to next time"; then
- eval set "$i" # $i comes from auto_check function
- time="$1"
- exe_time_old="$2"
- gap="$3"
- exe_time="$(eval date -d \"$time\")"
- # If the target date is already history, add +gap for the exec time:
- if [[ "$((`date +%s -d "$exe_time"`))" -lt "$((`date +%s`))" ]]; then
- exe_time="$(eval date -d \"$time+$gap\")"
- fi
- time_new="\"$time\" \"$exe_time\" \"$gap\""
- # Update todo database:
- sed -i '/'"'$ident'"'/s/'"'$i'"'/'"'$time_new'"'/g' $todo_database
- # Update cron:
- find_time_details "$exe_time"
- # Only add updated task, if target time is less than year from now:
- if [[ "$TARGET" -lt "$(( $NOW + 24*60*60*365 ))" ]]; then
- echo "$mins $hours $date $month * $DIR/$zero '$ident' '$task' '$time_new'" >> $cron
- fi
- fi
- else
- if zenity --question --cancel-label="Nope, leave it be" --ok-label="OK" --text="It looks like task\n\n\"$task\"\n\nhas failed to remind.\n(execution time should have been at $time)\n\nPress OK to remove this reminder date from database."; then
- # Check whether there are any other exe times for this task;
- # if not, delete the task:
- eval set "$(grep $ident $todo_database)"
- if [[ "$#" == "3" ]]; then
- # Meaning this was the only exe date, so delete this entry:
- sed -i '/'"'$ident'"'/d' $todo_database
- else
- # Meaning there are other exe dates present; remove only this exe time:
- sed -i '/'"'$ident'"'/s/'" '$i'"'//g' $todo_database
- fi
- fi
- fi
- elif [[ "$TARGET" -gt "$(( $NOW + 24*60*60*365 ))" ]]; then
- skip="True"
- fi
- else # this part is called only for non-repetitive tasks while adding new tasks
- unset update skip add
- if [[ "$TARGET" -lt "$NOW" ]] && [[ "$year" == "$current_year" ]]; then
- if [[ "$UI" == "True" ]]; then
- if zenity --question --text="Selected date ($datetime) for task\n\n\"$task\"\n\nis already history this year.\nWant to add this task for the next year?\n(in that case exe time would be at \"$date. $month_char $(( $current_year + 1 )) at $hrs_mins\")\nAnswering \"No\" will delete this task from the todo database!"; then
- update="True"
- else
- skip="True"
- fi
- else # i.e. it's command-line
- clear
- echo -e "Selected date ($datetime) for task\n\n\"$task\"\n\nis already history this year.\nWant to add this task for the next year?\n(in that case exe time would be at \"$date. $month_char $(( $current_year + 1 )) at $hrs_mins\")\n\nAnswering \"n\" will delete this task from the todo database!\n\n(y/n)?"
- while :; do
- read yno
- case $yno in
- [yY] | YEs | YES | Yes | yes )
- update="True"
- echo "Ok, adding this task to next year...";
- break
- ;;
- [nN] | NO | No | no )
- skip="True"
- echo "Deleting this task...";
- break
- ;;
- *) echo "Invalid input, try again. (either y/n is accepted)"
- ;;
- esac
- done
- fi
- if [[ "$update" == "True" ]]; then
- entry2="$(( $current_year + 1 ))-$month-$date $hrs_mins"
- find_time_details "$entry2"
- entry2="$datetime"
- fi
- # Skip the jobs far in the future, but install those that are less
- # than one year from now (this comes from the cron limitation):
- elif [[ "$TARGET" -gt "$(( $NOW + 24*60*60*365 ))" ]]; then
- skip="True"
- add="True" # i.e. job will be added to db, but not into cron
- # Skip the jobs that are in the past and skip tose tasks:
- elif [[ "$year" -lt "$current_year" ]]; then
- if [[ "$UI" == "1" ]]; then
- zenity --info --text="Selected date for task \"$task\" is already history. Will skip this."
- else # i.e. it's command-line
- clear
- echo -e "Selected year for task \"$task\" is $year.\nWhy the hell would you make a to-do note for past date?\n\nWill skip this task."
- fi
- skip="True"
- fi
- fi
- }
- function add_task () {
- # Function that's responsible for adding new tasks into database.
- # Note it handles two cases - CLI and GUI.
- generate_ident $todo_database
- if [[ "$UI" == "True" ]]; then
- task=$(zenity --width="500" --entry --text "Enter the task:")
- [[ -z "$task" ]] && return # return, if either nothing was input or zenity prompt was closed
- # Replace single quotes and &-signs:
- task=$(echo "$task" | sed -e 's/'\''/''\`/g' | sed -e 's/'\&'/''\+/g')
- until [[ "$another_date" == "False" ]]; do
- unset opt skip add
- exe_date=$(zenity --calendar --date-format=%Y-%m-%d --text "Pick a day" --title "$task")
- [[ -z "$exe_date" ]] && return
- time=$(zenity --entry --text "Enter the time:" --entry-text "e.g. 19:45")
- [[ -z "$time" ]] && return
- while [[ "$((`date +%s -d "$time"`))" == "0" ]]; do
- time=$(zenity --entry --text "Bad time! Try again:" --entry-text "e.g. 19:45")
- done
- [[ -z "$time" ]] && return
- find_time_details "$exe_date $time"
- entry2="$datetime" # Creates initial exe time for non-rep task;
- if zenity --question --text="Is this repetitive exe date?"; then
- opt1="$month_char $date at $hrs_mins"
- opt2="$day at $hrs_mins"
- opt3="day at $hrs_mins"
- opt4="month on $date th"
- until [[ -n "$opt" ]]; do
- opt=`zenity --list --text="When do you want this task to remind?" \
- --radiolist --column "" --column "Every..." TRUE "$opt1" FALSE "$opt2" FALSE "$opt3" FALSE "$opt4"`
- done
- case $opt in
- "$opt1") entry2="$month_char $date $hrs_mins"
- gap="next year"
- ;;
- "$opt2") entry2="$day $hrs_mins"
- gap="next week"
- ;;
- "$opt3") entry2="$hrs_mins"
- gap="day"
- ;;
- "$opt4") entry2="$month_char $date $hrs_mins"
- gap="month"
- ;;
- esac
- build_repetitive_dateline "$entry2" # this function creates new $entry2
- else
- check_time "$entry2" # Checks exe time validity for non-rep task;
- fi
- # Add new time to the date_arr:
- if [[ "$skip" != "True" ]] || [[ "$add" == "True" ]]; then
- date_arr=("${date_arr[@]}" "'$entry2'" )
- if [[ "$skip" != "True" ]]; then
- eval set "$entry2"
- [[ "$#" == "3" ]] && find_time_details "$2" || find_time_details "$entry2"
- echo "$mins $hours $date $month * $DIR/$zero '$ident' '$task' '$entry2'" >> $cron
- fi
- fi
- # Ask user if another exe time is needed:
- zenity --question --text="Would you like to add another reminder date for this task?" || another_date="False"
- done
- else # Meaning we're dealing with CLI here.
- echo -e "Enter the task:\n"
- read task
- while [[ -z "$task" ]]; do
- clear
- echo "No characters were entered; try again."
- read task
- done
- # Replace single quotes and &-signs:
- task=$(echo "$task" | sed -e 's/'\''/''\`/g' | sed -e 's/'\&'/''\+/g')
- until [[ "$another_date" == "False" ]]; do
- unset repetitive skip add monthtag daytag
- clear
- echo -e "Enter date:\n(only certain formats are accepted. See \"$zero -h | --help\" for usage.)"
- read date_manual
- while [[ -z "$date_manual" ]]; do
- clear
- echo "No characters were entered; try again."
- read date_manual
- done
- eval set "$date_manual"
- if [[ "$1" == "r" ]]; then
- shift
- repetitive="True"
- case $1 in
- month)
- shift
- monthtag="True"
- ;;
- day)
- shift
- daytag="True"
- ;;
- esac
- fi
- while [[ "$(eval date +%s -d \"$@\")" == "0" ]] || [[ "$(eval date +%s -d \"$@\")" == "" ]]; do
- clear
- echo -e "Bad date format! Try again:"
- read date_manual
- while [[ -z "$date_manual" ]]; do
- clear
- echo "No characters were entered; try again."
- read date_manual
- done
- eval set "$date_manual"
- if [[ "$1" == "r" ]]; then
- shift
- repetitive="True"
- case $1 in
- month)
- shift
- monthtag="True"
- ;;
- day)
- shift
- daytag="True"
- ;;
- esac
- fi
- done
- # Find the time details (mins, hrs, date etc using find_time_details function:
- if [[ "$monthtag" == "True" ]]; then
- current_month=$(eval date +%b -d \"now\")
- find_time_details "$current_month $@" # without the 'Mon', date calls from find_time_details might fail
- else
- find_time_details "$@"
- fi
- entry2="$datetime"
- [[ "$repetitive" == "True" ]] && { build_repetitive_dateline "$@"; } \
- || { check_time "$entry2"; }
- # Add new time to the date_arr:
- if [[ "$skip" != "True" ]] || [[ "$add" == "True" ]]; then
- date_arr=("${date_arr[@]}" "'$entry2'" )
- if [[ "$skip" != "True" ]]; then
- eval set "$entry2"
- [[ "$#" == "3" ]] && find_time_details "$2" || find_time_details "$entry2"
- echo "$mins $hours $date $month * $DIR/$zero '$ident' '$task' '$entry2'" >> $cron
- fi
- fi
- # Ask user if another exe time is needed:
- echo -e "Would you like to add another reminder date for this task? (y/n)"
- while :; do
- read yno
- case $yno in
- [yY] | YEs | YES | Yes | yes )
- break
- ;;
- [nN] | NO | No | no )
- another_date="False"
- break
- ;;
- *) echo "Invalid input, try again. (either y/n is accepted)"
- ;;
- esac
- done
- done
- fi
- # If task has valid dates, enter it into database and install cron:
- if [[ "${#date_arr[*]}" != "0" ]]; then
- echo "'$ident' '$task' ${date_arr[@]}" >> $todo_database
- crontab $cron
- fi
- }
- function add_bd () {
- # Function that's responsible for adding new birthdays into database.
- # Note it handles two cases - CLI and GUI.
- generate_ident $todo_database
- if [[ "$UI" == "True" ]]; then
- name=$(zenity --entry --text "Enter name:")
- [[ -z "$name" ]] && return # Return if no characters
- # Replace single quotes with back-quotes within the name:
- name=$(echo "$name" | sed -e 's/'\''/''\`/g')
- exe_date=$(zenity --calendar --date-format=%Y-%m-%d --text "Pick a day" --title "$name")
- [[ -z "$exe_date" ]] && return
- date=$(date +%d -d "$exe_date") > /dev/null 2>&1
- month=$(date +%b -d "$exe_date") > /dev/null 2>&1
- if zenity --question --text="Would you want this birthday to remind also one week before?"; then
- important="True"
- fi
- else # Meaning we're dealing with CLI here.
- echo -e "Enter the name:"
- read name
- while [[ -z "$name" ]]; do
- clear
- echo "No characters were entered; try again"
- read name
- done
- # Replace single quotes with back-quotes within the name:
- name=$(echo "$name" | sed -e 's/'\''/''\`/g')
- echo -e "Enter his/her birthday (in a format '28 Jul'):"
- read birthday_date
- while [[ -z "$birthday_date" ]]; do
- clear
- echo "No characters were entered; try again."
- read birthday_date
- done
- eval set "$birthday_date"
- [[ "$1" == "i" ]] && { important="True"; shift; }
- # Check if the entered date makes any sense:
- while [[ "$(eval date +%s -d \"$@\")" == "0" ]] || [[ "$(eval date +%s -d \"$@\")" == "" ]]; do
- clear
- echo -e "Birthday date has to be in a format 'DD Mmm' e.g. 18 Jun, or 'i DD Mmm'\n"
- read birthday_date
- while [[ -z "$birthday_date" ]]; do
- clear
- echo "No characters were entered; try again."
- read birthday_date
- done
- eval set "$birthday_date"
- [[ "$1" == "i" ]] && { important="True"; shift; }
- done
- date=$(eval date +%d -d \"$@\") > /dev/null 2>&1
- month=$(eval date +%b -d \"$@\") > /dev/null 2>&1
- fi
- if [[ "$important" == "True" ]]; then
- echo "'$ident' '$name' 'i' '$date $month'" >> $birthday_database
- else
- echo "'$ident' '$name' '$date $month'" >> $birthday_database
- fi
- }
- function auto_check() {
- # Function that'll check whether any tasks have failed to remind or there are
- # any upcoming birthdays and also add tasks that are less than a year from current moment into cron:
- auto_check="True"
- # Rebuild cron file:
- echo -e "# This is the cron file used by the TO-DO manager ($DIR/$zero).\n#------------------------------------------------------------------------" > $cron
- while read line; do
- eval set "$line"
- ident="$1"
- task="$2"
- shift
- shift
- for i in "$@"; do
- unset skip repetitive
- eval set "$i"
- [[ "$#" == "3" ]] && { time="$2"; repetitive="True"; } || time="$i"
- find_time_details "$time"
- check_time "$time"
- [[ "$skip" == "True" ]] && continue
- echo "$mins $hours $date $month * $DIR/$zero '$ident' '$task' '$i'" >> $cron
- done
- done < $todo_database
- crontab $cron
- # Birthday database cheker:
- while read line; do
- unset important
- eval set "$line"
- name="$2"
- shift
- shift
- # If date line's first variable is 'i', then remind this person's birthday also one week before:
- [[ "$1" == "i" ]] && { shift; important="True"; }
- time="$@"
- eval_date="$(date +%F --date="$time")"
- if [[ "$important" == "True" ]] && [[ "$eval_date" == "$(date +%F --date="week")" ]]; then
- date=$(eval date +%d -d \"$time\") > /dev/null 2>&1
- month=$(eval date +%b -d \"$time\") > /dev/null 2>&1
- notify-send -t 0 -i gtk-dialog-info "$name's birthday is next week! ($date. $month)"
- continue
- elif [[ "$eval_date" == "$(date +%F --date="today")" ]]; then
- notify-send -t 0 -i gtk-dialog-info "$name's birthday is TODAY!"
- continue
- elif [[ "$eval_date" == "$(date +%F --date="tomorrow")" ]]; then
- date=$(eval date +%d -d \"$time\") > /dev/null 2>&1
- month=$(eval date +%b -d \"$time\") > /dev/null 2>&1
- notify-send -t 0 -i gtk-dialog-info "$name's birthday is tomorrow ($date. $month)"
- fi
- done < $birthday_database
- }
- function list_task() {
- # Function for listing all the tasks installed in todo database.
- # Create the array for zenity:
- count=0
- while read line; do
- eval set "$line"
- unset first_time
- count2="1"
- task="$2"
- shift # 'cause ID is not needed here
- shift # discards of task
- for i in "$@"; do
- eval set "$i"
- [[ "$#" == "3" ]] && { exe_time="$2"; rep="X"; } || { rep=" "; exe_time="$i"; }
- if [[ "$first_time" == "False" ]]; then
- arr=("${arr[@]}" "$count.$count2" "$rep" " " "$exe_time" )
- let count2=$count2+1
- else
- let count=$count+1
- arr=("${arr[@]}" "$count" "$rep" "$task" "$exe_time" )
- first_time="False"
- fi
- done
- done < $todo_database
- # List tasks:
- foo=$(zenity --list --width="800" --height="300" --text="Current tasks:" \
- --column "#" --column "rep" --column "Task" --column "Exe time" "${arr[@]}")
- }
- function list_bd() {
- # Function for listing all the names installed in birthday database.
- # Create the array for zenity:
- count=0
- while read line; do
- eval set "$line"
- imp=" "
- name=$2
- [[ "$3" == "i" ]] && { imp="X"; exe_time="$4"; } || exe_time="$3"
- let count=$count+1
- arr=("${arr[@]}" "$count" "$imp" "$name" "$exe_time" )
- done < $birthday_database
- # List birthdays:
- foo=$(zenity --list --width="800" --height="300" --text="Entered birthday entries:" \
- --column "#" --column "i" --column "Name" --column "Birthday" "${arr[@]}")
- }
- function delete() {
- # Will create selection dialog for selecting tasks to be deleted.
- shift # Gets rid of potential -d/--delete flag
- nr_of_lines=$(sed -n "$=" $todo_database)
- if [[ -z "$@" ]]; then # i.e. no more flags were provided, meaning GUI
- # Create the array for zenity:
- while read line; do
- eval set "$line"
- ID="$1"
- task="$2"
- arr=("${arr[@]}" "FALSE" "$ID" "$task" )
- done < $todo_database
- # Display task selection dialog:
- ans=$(zenity --list --width="800" --height="300" --text="Pick task(s) to be deleted:" \
- --checklist --column "Pick" --hide-column=2 --column "Task ID" --column "Task" "${arr[@]}" --separator=" ")
- [[ -n $ans ]] && { eval set "$ans"; } || { set ""; }
- if [[ "$#" -gt "3" ]]; then
- if zenity --question --text="You've selected quite a few tasks to delete;\nwant to skip deletion confirmation?"; then
- skip_confirm="True"
- fi
- fi
- for i in $ans; do # If nothing was selected, script simply skips this
- eval set "$(grep $i $todo_database)"
- task="$2"
- if [[ "$skip_confirm" != "True" ]]; then
- if zenity --question --text="Sure you want to delete task\n$task?"; then
- # Delete task from todo_database
- sed -i '/'"$i"'/d' $todo_database
- # ... and from cron:
- sed -i '/'"$i"'/d' $cron
- fi
- else
- # Delete task from todo_database
- sed -i '/'"$i"'/d' $todo_database
- # ... and from cron:
- sed -i '/'"$i"'/d' $cron
- fi
- done
- crontab $cron
- return
- # CLI part from here:
- # This part deletes by the task #nr entered by the user:
- elif [[ "$#" != "1" ]] || [[ "$1" -le "0" ]]; then
- print_error "few_args"
- # Check that user isn't asking deletion of task that's non-existent:
- elif [[ "$1" -gt "$nr_of_lines" ]]; then
- echo -e "Requested task nr $1 doesn't exist.\nNr of tasks currently in database is $nr_of_lines."; exit 1
- fi
- eval set "$(sed -n "$1"p $todo_database)"
- ID="$1"
- task="$2"
- echo -e "Are you sure you want to delete task"; $bold
- echo -e "$task\n"; $offbold
- echo "(y/n)?"
- while :; do
- read yno
- case $yno in
- [yY] | YEs | YES | Yes | yes )
- echo "Ok, deleting task '$task'...";
- # Delete task from todo_database
- sed -i '/'"$ID"'/d' $todo_database
- # ... and from cron:
- sed -i '/'"$ID"'/d' $cron
- crontab $cron
- break
- ;;
- [nN] | NO | No | no )
- echo "Won't delete.";
- break
- ;;
- *) echo "Invalid input, try again. (either y/n is accepted)"
- ;;
- esac
- done
- }
- function delete_bd() {
- # Will create selection dialog for selecting names to be deleted.
- shift # Gets rid of potential -db flag
- nr_of_lines=$(sed -n "$=" $birthday_database)
- if [[ -z "$@" ]]; then # i.e. no flags were provided, meaning GUI
- # Create the array for zenity:
- while read line; do
- eval set "$line"
- ID="$1"
- name="$2"
- arr=("${arr[@]}" "FALSE" "$ID" "$name" )
- done < $birthday_database
- # Display name selection dialog:
- ans=$(zenity --list --width="800" --height="300" --text="Pick birthday entries to be deleted:" \
- --checklist --column "Pick" --hide-column=2 --column "Birthday ID" --column "Name" "${arr[@]}" --separator=" ")
- [[ -n $ans ]] && { eval set "$ans"; } || { set ""; }
- if [[ "$#" -gt "3" ]]; then
- if zenity --question --text="You've selected quite a few names to delete;\nwant to skip deletion confirmation?"; then
- skip_confirm="True"
- fi
- fi
- for i in $ans; do # If nothing was selected, script simply skips this
- eval set "$(grep $i $birthday_database)"
- ID="$1"
- name="$2"
- if [[ "$skip_confirm" != "True" ]]; then
- if zenity --question --text="Sure you want to delete entry\n$name?"; then
- # Delete entry from birthday_database
- sed -i '/'"$i"'/d' $birthday_database
- fi
- else
- # Delete entry from birthday_database
- sed -i '/'"$i"'/d' $birthday_database
- fi
- done
- return
- # CLI from here on:
- # This part deletes by the entry #nr entered by the user:
- elif [[ "$#" != "1" ]] || [[ "$1" -le "0" ]]; then
- print_error "few_args"
- # Check that user isn't asking deletion of entry that's non-existent:
- elif [[ "$1" -gt "$nr_of_lines" ]]; then
- echo -e "Requested entry nr $1 doesn't exist.\nNr of entries currently in database is $nr_of_lines."; exit 1
- fi
- eval set "$(sed -n "$1"p $birthday_database)"
- ID="$1"
- name="$2"
- echo -e "Are you sure you want to delete entry"; $bold
- echo -e "$name\n"; $offbold
- echo "(y/n)?"
- while :; do
- read yno
- case $yno in
- [yY] | YEs | YES | Yes | yes )
- echo "Ok, deleting entry '$name'...";
- # Delete entry from birthday_database
- sed -i '/'"$ID"'/d' $birthday_database
- break
- ;;
- [nN] | NO | No | no )
- echo "Won't delete.";
- break
- ;;
- *) echo "Invalid input, try again. (either y/n is accepted)"
- ;;
- esac
- done
- }
- function cronjob() {
- # Cron will feed jobs here.
- ident="$1"
- task="$2"
- # Part that displays the task reminder on desktop:
- notify-send -t 0 -i gtk-dialog-info "$task"
- old_date="$3"
- # Delete old entry from cron:
- sed -i '/'"'$ident' '$task' '$old_date'"'/d' $cron
- eval set "$old_date"
- if [[ "$#" == "3" ]]; then
- time="$1"
- exe_time_old="$2"
- gap="$3"
- exe_time="$(eval date -d \"$time\")"
- # If the target date is already history, add +gap for the exec time:
- if [[ "$((`date +%s -d "$exe_time"`))" -lt "$((`date +%s`))" ]]; then
- exe_time="$(eval date -d \"$time+$gap\")"
- fi
- time_new="\"$time\" \"$exe_time\" \"$gap\""
- # Update todo database:
- sed -i '/'"'$ident'"'/s/'"'$old_date'"'/'"'$time_new'"'/g' $todo_database
- # Update cron:
- find_time_details "$exe_time"
- # Only add updated task, if target time is less than year from now:
- if [[ "$TARGET" -lt "$(( $NOW + 24*60*60*365 ))" ]]; then
- echo "$mins $hours $date $month * $DIR/$zero '$ident' '$task' '$time_new'" >> $cron
- fi
- else # meaning non-rep date
- # Check whether there are any other exe times for this task;
- # if not, delete the task:
- eval set "$(grep $ident $todo_database)"
- if [[ "$#" == "3" ]]; then
- # Meaning this was the only exe date, so delete this entry:
- sed -i '/'"'$ident'"'/d' $todo_database
- else
- # Meaning there are other exe dates pending; remove only this particular exe time:
- sed -i '/'"'$ident'"'/s/'" '$old_date'"'//g' $todo_database
- fi
- fi
- # Install the renewed crontab:
- crontab $cron
- }
- function install_() {
- # Function for moving scriptfile into $install_path and adding cronjobs
- # into '/etc/cron.d/' to run this script at boot-up and some specific time in a day.
- # Do not use this. It's a dirty-dirty hack.
- if [[ "$(whoami)" == "root" ]]; then
- echo "Please do not start installation being root. Abort"; exit
- fi
- escaped_path=$(echo $install_path | sed -e 's/\([[\/.*]\|\]\)/\\&/g')
- non_root="$(whoami)"
- # Check whether $install_path even exists:
- [[ -d "$install_path" ]] || { notify-send -t 0 -i gtk-dialog-error "Default installation directory $install_path does not exist. Edit scriptfile and change installation destination dir. Aborting."; exit 1; }
- if [[ "$UI" == "True" ]]; then
- zenity --question --text="Looks like the script isn't installed.\nThis will install the script into $install_path\nand add cronjobs into $todo_crontab that will run script\nwith --auto flag at every midnight and system startup.\n\n(You can alternatively install by running\n'$DIR/$zero -i' in terminal.)\n PLEASE NOTE IT'S NOT RECOMMENDED TO USE AUTOMATED INSTALLATION\n\nYou'll be better off:\n a) copying this file to /usr/local/bin\n b) adding cron job to run this script once a day with '--auto' flag\n c) adding this script to startup applications, so it would also be run\n with '--auto' flag at startup\n\nContinue anyway?" || exit
- # Check which graphical sudo program can be used:
- for Gsudo in gksudo beesu kdesu gksu ktsuss NoSudo; do command -v $Gsudo >/dev/null && break; done
- if [[ "$Gsudo" == "NoSudo" ]]; then
- notify-send -t 0 -i gtk-dialog-error "No graphical sudo found. Install script by running '$DIR/$zero -i' in terminal! Aborting."; exit 1
- fi
- # Skip file move if script is already at $install_path:
- if [[ "$DIR" != "$install_path" ]]; then
- if [[ -f "$install_path/$zero" ]]; then
- if zenity --question --text="There already is a file called '$zero' in $install_path\nOverwrite?"; then
- $Gsudo mv $DIR/$zero $install_path/$zero
- echo "Ok, overwriting '$install_path/$zero'...";
- notify-send -t 3000 -i gtk-dialog-info "Ok, overwriting '$install_path/$zero'..."
- else
- echo "Won't overwrite.";
- notify-send -t 3000 -i gtk-dialog-info "Ok, won't overwrite."
- fi
- else
- $Gsudo mv $DIR/$zero $install_path/$zero
- fi
- # Make sure file move was successful:
- [[ -f "$install_path/$zero" ]] && { DIR="$install_path"; $Gsudo chmod +x $install_path/$zero; } || \
- { notify-send -t 0 -i gtk-dialog-error "Could not move the file, aborting."; exit 1; }
- fi
- # Create a file in /etc/pm/sleep.d/ which will execute script with --auto flag after suspension:
- if [[ -d "/etc/pm/sleep.d/" ]] && ! [[ -f "/etc/pm/sleep.d/todo_exe.sh" ]]; then
- echo -e "#!/bin/bash\ncase \$1 in\nresume)\nsleep 5\n$DIR/$zero --auto\n;;\nesac" > $tmp
- $Gsudo mv $tmp /etc/pm/sleep.d/todo_exe.sh
- $Gsudo chown root /etc/pm/sleep.d/todo_exe.sh
- $Gsudo chmod +x /etc/pm/sleep.d/todo_exe.sh
- fi
- # Check if system has $todo_crontab:
- if ! [[ -f "$todo_crontab" ]]; then
- # Does $todo_cron_dir dir exist?:
- [[ -d "$todo_cron_dir" ]] || { notify-send -t 0 -i gtk-dialog-error "Oops, it looks like your system has no such folder as as $todo_cron_dir :(. Can't install cronjobs, please contact laur.aliste [at] gmail and report this error"; exit 1; }
- echo -e "# Custom crontab used by $DIR/$zero\n\nSHELL=/bin/bash\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n\n# m h dom mon dow user command\n#" > $tmp
- else
- cat $todo_crontab > $tmp # Copies crontab file into tmp-file for processing.
- fi
- # Create cronjob entries that'll run the script at certain times:
- # Check whether there already are cronjobs for this script:
- #if [[ -n "$(grep "$USER $DIR/$zero --auto" $tmp)" ]]; then
- # zenity --question --text="There already are cron entries for this script in $todo_crontab\nCreate new one?" || return
- #fi
- time=$(zenity --entry --text "What time every day would you like the script to run?\n(leave blank for default midnight)")
- while [[ "$(eval date +%s -d \"$time\")" == "0" ]] || [[ "$(eval date +%s -d \"$time\")" == "" ]]; do
- time=$(zenity --entry --text "Bad time! Try again:" --entry-text "e.g. 19:45")
- done
- [[ -z "$time" ]] && time="00:00"
- find_time_details "$time"
- notify-send -t 3000 -i gtk-dialog-info "Ok, adding cron entry..."
- echo "Ok, adding cron entry...";
- sed -i '/'"$USER $escaped_path\/$zero --auto"'/d' $tmp
- echo "$mins $hours * * * $USER $install_path/$zero --auto" >> $tmp
- $Gsudo mv $tmp $todo_crontab
- $Gsudo chown root $todo_crontab
- # Create init file in etc/init.d/ and add link, so script would be started at startup:
- # This IS NOT recommended!
- # Check if system has /etc/init.d/:
- if ! [ -f /etc/init.d/todo_script_init ]; then
- [ -d /etc/init.d/ ] || { notify-send -t 0 -i gtk-dialog-error "/etc/init.d/ dir not found. Please report this problem to laur.aliste ät gmail."; exit; }
- printf "#! /bin/bash\n\n### BEGIN INIT INFO
- # Provides: todo-script autocheck at startup
- # Required-Start: \$all
- # Required-Stop:
- # X-Start-Before:
- # Default-Start: 2 3 4 5
- # Default-Stop:
- # Description: runs 'todo --auto' at startup, when xserver has started and user is logged on.
- ### END INIT INFO
- usr=\"$non_root\" # User whose logon to wait for
- script=\"$install_path/$zero --auto\"
- ###########################################################
- case \"\$1\" in
- start)
- # Wait until X is running and required user logged in:
- count=0
- until [[ \"\$(tty)\" != \"\/dev\/tty1\" ]] && [[ \"\$(who | cut -d' ' -f1 | sort | uniq)\" == \"\$usr\" ]]; do
- sleep 5
- let count=\$count+1
- if [[ \"\$count\" == \"10\" ]]; then
- echo \"Xserver hasn't started or other error occurred. Abort\"; exit 1
- fi
- done
- # Run the script as YOURUSERNAME instead of root:
- su - \$usr -c '\$script'
- ;;
- stop)
- :
- ;;
- esac
- exit 0" > $tmp
- $Gsudo mv $tmp /etc/init.d/todo_script_init
- $Gsudo chmod +x /etc/init.d/todo_script_init
- # ... create the link:
- sudo insserv todo_script_init
- fi
- else # CLI
- clear
- echo -e "Looks like the script isn't installed.\nThis will install the script into $install_path\nand add cronjobs into $todo_crontab that will run script\nwith --auto flag at every midnight and system startup.\n\n(You can alternatively install by running\n'$DIR/$zero -i' in terminal.)\n PLEASE NOTE IT'S NOT RECOMMENDED TO USE AUTOMATED INSTALLATION\n\nYou'll be better off:\n a) copying this file to /usr/local/bin\n b) adding cron job to run this script once a day with '--auto' flag\n c) adding this script to startup applications, so it would also be run\n with '--auto' flag at startup\n\nContinue anyway? (y/n)\n"
- read proceed
- [[ "$proceed" == "y" ]] && { echo "Ok"; } || { echo "Abort."; exit; }
- # Skip file move if script is already at $install_path:
- if [[ "$DIR" != "$install_path" ]]; then
- if [[ -f "$install_path/$zero" ]]; then
- clear
- echo -e "There already is a file called '$zero' in $install_path\nOverwrite (y/n)?"
- while :; do
- read yno
- case $yno in
- [yY] | YEs | YES | Yes | yes )
- echo "Ok, overwriting '$install_path/$zero'...";
- sudo mv $DIR/$zero $install_path/$zero
- break
- ;;
- [nN] | NO | No | no )
- echo "Won't overwrite.";
- break
- ;;
- *) echo "Invalid input, try again. (either y/n is accepted)"
- ;;
- esac
- done
- else
- sudo mv $DIR/$zero $install_path/$zero
- fi
- # Make sure file move was successful:
- [[ -f "$install_path/$zero" ]] && { DIR="$install_path"; sudo chmod +x $install_path/$zero; } \
- || { echo "Could not move the file, abort."; exit 1; }
- fi
- # Create a file in /etc/pm/sleep.d/ which will execute script with --auto flag after suspension:
- if [[ -d "/etc/pm/sleep.d/" ]] && ! [[ -f "/etc/pm/sleep.d/todo_exe.sh" ]]; then
- echo -e "#!/bin/bash\ncase \$1 in\nresume)\nsleep 5\n$DIR/$zero --auto\n;;\nesac" > $tmp
- sudo mv $tmp /etc/pm/sleep.d/todo_exe.sh
- sudo chown root /etc/pm/sleep.d/todo_exe.sh
- sudo chmod +x /etc/pm/sleep.d/todo_exe.sh
- fi
- clear
- # Check if system has $todo_crontab:
- if ! [[ -f "$todo_crontab" ]]; then
- # Does $todo_cron_dir dir exist?:
- [[ -d "$todo_cron_dir" ]] || { echo -e "Oops, it looks like your system has no such folder as as $todo_cron_dir :(\nCan't install cronjobs, please contact laur.aliste [at] gmail and report this error"; exit 1; }
- echo -e "# Custom crontab used by $DIR/$zero\n\nSHELL=/bin/bash\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n\n# m h dom mon dow user command\n#" > $tmp
- else
- cat $todo_crontab > $tmp
- fi
- # Create cronjob entries that'll run the script at certain times:
- # Check whether there already are cronjobs for this script:
- #if [[ -n "$(grep "$USER $DIR/$zero --auto" $tmp)" ]]; then
- # echo -e "There already are cron entries for this script in $todo_crontab\nCreate new one? (y/n)?"
- # while :; do
- # read yno
- # case $yno in
- # [yY] | YEs | YES | Yes | yes )
- # break
- # ;;
- # [nN] | NO | No | no )
- # echo "Won't create new crontab entries."; return
- # ;;
- # *) echo "Invalid input, try again. (either y/n is accepted)"
- # ;;
- # esac
- # done
- #fi
- echo -e "What time every day would you like the script to run?\n(it'll run in the background)\n(leave blank for default midnight)"
- read time
- [[ -z "$time" ]] && time="00:00"
- while [[ "$(eval date +%s -d \"$time\")" == "0" ]] || [[ "$(eval date +%s -d \"$time\")" == "" ]]; do
- clear
- echo -e "Bad time format, try again! (e.g. 00:00, 15:30, 1200, 1430)"
- read time
- [[ -z "$time" ]] && time="00:00"
- done
- find_time_details "$time"
- echo "Ok, adding cron entry...";
- sed -i '/'"$USER $escaped_path\/$zero --auto"'/d' $tmp
- echo "$mins $hours * * * $USER $install_path/$zero --auto" >> $tmp
- sudo mv $tmp $todo_crontab
- sudo chown root $todo_crontab
- # Create init file in etc/init.d/ and add link, so script would be started at startup:
- # This IS NOT recommended!
- # Check if system has /etc/init.d/:
- if ! [ -f /etc/init.d/todo_script_init ]; then
- [ -d /etc/init.d/ ] || { echo "/etc/init.d/ dir not found. Please report this problem to laur.aliste ät gmail."; exit; }
- printf "#! /bin/bash\n\n### BEGIN INIT INFO
- # Provides: todo-script autocheck at startup
- # Required-Start: \$all
- # Required-Stop:
- # X-Start-Before:
- # Default-Start: 2 3 4 5
- # Default-Stop:
- # Description: runs 'todo --auto' at startup, when xserver has started and user is logged on.
- ### END INIT INFO
- usr=\"$non_root\" # User whose logon to wait for
- script=\"$install_path/$zero --auto\"
- ###########################################################
- case \"\$1\" in
- start)
- # Wait until X is running and required user logged in:
- count=0
- until [[ \"\$(tty)\" != \"\/dev\/tty1\" ]] && [[ \"\$(who | cut -d' ' -f1 | sort | uniq)\" == \"\$usr\" ]]; do
- sleep 5
- let count=\$count+1
- if [[ \"\$count\" == \"10\" ]]; then
- echo \"Xserver hasn't started or other error occurred. Abort\"; exit 1
- fi
- done
- # Run the script as YOURUSERNAME instead of root:
- su - \$usr -c '\$script'
- ;;
- stop)
- :
- ;;
- esac
- exit 0" > $tmp
- sudo mv $tmp /etc/init.d/todo_script_init
- sudo chmod +x /etc/init.d/todo_script_init
- # ... create the link:
- sudo insserv todo_script_init
- fi
- fi
- }
- function uninstall_() {
- # Note when script isn't located at $install_path, one will be first
- # prompted with installation.
- echo "Sure you want to uninstall this script and corresponding files? (y/n)?"
- while :; do
- read yno
- case $yno in
- [yY] | YEs | YES | Yes | yes )
- break
- ;;
- [nN] | NO | No | no )
- clear
- echo "Ok, won't uninstall."; exit
- ;;
- *) echo "Invalid input, try again. (either y/n is accepted)"
- ;;
- esac
- done
- > $tmp
- crontab $tmp # Clears currently installed cronjobs
- rm $tmp
- sudo rm $todo_crontab
- sudo rm /etc/pm/sleep.d/todo_exe.sh
- sudo rm $cron
- if [ -f /etc/init.d/todo_script_init ]; then
- sudo rm /etc/init.d/todo_script_init
- sudo update-rc.d -f todo_script_init remove
- fi
- echo "Delete also birthday and tasks files? (y/n)?"
- while :; do
- read yno
- case $yno in
- [yY] | YEs | YES | Yes | yes )
- sudo rm $birthday_database
- sudo rm $todo_database
- break
- ;;
- [nN] | NO | No | no )
- clear
- echo "Ok, won't delete birthday and tasks files."
- break
- ;;
- *) echo "Invalid input, try again. (either y/n is accepted)"
- ;;
- esac
- done
- sudo rm $DIR/$zero # Finally, remove the scriptfile itself
- echo "All done, goodbye!"; exit
- }
- ################################## START #######################################
- # Update DISPLAY values if incorrect (check only if script is not run by cron):
- if [[ "$disp" != "$disp2" ]]; then
- if [[ "$1" != "--auto" && "$1" != $tag1*$tag2 ]] && [[ "$whoami" != "root" ]] ;then
- [[ "$DIR" == "$install_path" ]] && \
- { gsudo="sudo"; echo "Please enter password so some changes could be made to $zero:"; }
- $gsudo sed -i 's/'"export DISPLAY\=$disp"'/'"export DISPLAY\=$DISPLAY"'/g' $DIR/$zero
- clear
- $gsudo sed -i 's/'disp\=\"$disp\"'/'disp\=\"$DISPLAY\"'/g' $DIR/$zero
- echo "Updated some data within $zero, please restart."
- notify-send -t 3000 -i gtk-dialog-info "Updated some data within $DIR/$zero, please restart."; exit
- fi
- fi
- # Check if required programs are installed; if not, exit:
- check_program "notify-send" "zenity"
- # Create necessary files-folders if not existing:
- check_files "$todo_database" "$cron" "$birthday_database"
- # Just in case check the size of todo and birthday databases and cron file;
- # if size is larger than predefined value, display an error:
- check_filesize "$todo_database" "$birthday_database" "$cron"
- if [[ -z "$@" ]]; then # No command-line flags, meaning GUI usage
- opt_1="Add new tasks"
- opt_2="View entered tasks"
- opt_3="Delete tasks"
- opt_4="Add new birthdays"
- opt_5="View entered birthdays"
- opt_6="Delete birthdays"
- opt_7=" " # Simply a buffer-line to separate different blocks
- opt_8="Edit todo database"
- opt_9="Edit birthday database"
- opt_="dummy_value"
- UI="True"
- until [[ -z "$opt_" ]]; do
- NOW=$((`date +%s`))
- unset arr skip repetitive important add another_date date_arr opt skip_confirm opt_
- opt_=`zenity --width="500" --height="320" --list --cancel-label="Exit" --text="What would you like to do?" \
- --radiolist --column "" --column "Pick a task:" --hide-header TRUE "$opt_1" \
- FALSE "$opt_2" FALSE "$opt_3" FALSE "$opt_4" FALSE "$opt_5" FALSE "$opt_6" FALSE "$opt_7" FALSE "$opt_8" FALSE "$opt_9"`
- case $opt_ in
- "$opt_1") add_task
- ;;
- "$opt_2") list_task
- ;;
- "$opt_3") delete
- ;;
- "$opt_4") add_bd
- ;;
- "$opt_5") list_bd
- ;;
- "$opt_6") delete_bd
- ;;
- "$opt_7") opt_7=" What were you hoping to find here?"
- ;;
- "$opt_8")
- for txt_editor in gedit gvim NEdit sublime mousepad geany Not_Found; do
- command -v $txt_editor >/dev/null && break; done
- if [[ "$txt_editor" == "Not_Found" ]]; then
- notify-send -t 5000 -i gtk-dialog-error "Didn't find any graphical txt editors :("; exit 1
- fi
- $txt_editor $todo_database
- ;;
- "$opt_9")
- for txt_editor in gedit gvim NEdit sublime mousepad geany Not_Found; do
- command -v $txt_editor >/dev/null && break; done
- if [[ "$txt_editor" == "Not_Found" ]]; then
- notify-send -t 5000 -i gtk-dialog-error "Didn't find any graphical txt editors :("; exit 1
- fi
- $txt_editor $birthday_database
- ;;
- esac
- done
- exit
- fi
- case $1 in
- "-a" | "--add" ) # Graphical task addition:
- UI="True"
- add_task
- ;;
- "-am" | "--add_manual" ) # Terminal-based task addition:
- add_task
- ;;
- "-b" | "--birthday" ) # Graphical birthday addition:
- UI="True"
- add_bd
- ;;
- "-bm" | "--bd_manual" ) # Terminal-based birthday addition:
- add_bd
- ;;
- "--auto" ) # This flag has to be used on the system startup run and another random run once a day
- auto_check
- ;;
- "-l" | "--list" ) # Listing of current tasks in the todo database:
- list_task
- ;;
- "-lb" | "--list_bd" ) # Listing of current birthdays in the database:
- list_bd
- ;;
- "-d" | "--delete"| "--del" ) # Task deletion from the database:
- delete "$@"
- ;;
- "-db" | "--delete_bd"| "--del" ) # Birthday deletion from the database:
- delete_bd "$@"
- ;;
- $tag1*$tag2 ) # Cron feeds jobs into this part:
- cronjob "$@"
- ;;
- "-i" | "--install" ) # Moves file to $install_path and adds cronjobs
- install_
- ;;
- "-ui" | "--uninstall" )
- uninstall_
- ;;
- *) echo "Invalid input, try again."
- ;;
- esac
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement