Advertisement
metalx1000

Notes and Reminders BASH script

Oct 27th, 2018
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.47 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2018  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. notes="$HOME/.notes"
  21. minutes=15 #number of minutes for notifications
  22. url='http://filmsbykris.com/scripts/2018/note/'
  23.  
  24. function main(){
  25.   echo "Welcome..."
  26.   if [ "$1" = "add" ]
  27.   then
  28.     add
  29.   elif [ "$1" = "notify" ]
  30.   then
  31.     notify    
  32.   else
  33.     cat "$notes"
  34.   fi
  35.  
  36.   exit 0
  37. }
  38.  
  39. function notify(){
  40.   c=$(date +%s)
  41.   m=$(($minutes*60+$c))
  42.  
  43.   cat "$notes"|while read line;
  44.   do
  45.     time="$(echo $line|cut -d\| -f1)"
  46.     date="$(echo $line|cut -d\| -f2)"
  47.     title="$(echo $line|cut -d\| -f3)"
  48.     note="$(echo $line|cut -d\| -f4)"
  49.  
  50.     if (( $time > $c ))
  51.     then
  52.       if (( $time < $m ))
  53.       then
  54.         title="$(rawurlencode "$title")"
  55.         note="$(rawurlencode "$note")"
  56.         url="$url?title=$title&note=$note"
  57.         notify-send -t 0 "$title" "$note $url"
  58.       fi
  59.     fi
  60.   done
  61. }
  62.  
  63. function add(){
  64.   echo "When would you like to be reminded?"
  65.   read t
  66.  
  67.   date -d "$t" || (echo "bad date";exit 1)
  68.   time="$(date +%s -d "$t")"
  69.   date="$(date -d "$t")"
  70.   #echo "Setting reminder for $date"
  71.  
  72.   echo -n "Title:"
  73.   read title
  74.  
  75.   echo -n "Note:"
  76.   read note
  77.  
  78.   echo "$time|$date|$title|$note" >> "$notes"
  79. }
  80.  
  81.  
  82. rawurlencode() {
  83.   local string="${1}"
  84.   local strlen=${#string}
  85.   local encoded=""
  86.   local pos c o
  87.  
  88.   for (( pos=0 ; pos<strlen ; pos++ )); do
  89.      c=${string:$pos:1}
  90.      case "$c" in
  91.         [-_.~a-zA-Z0-9] ) o="${c}" ;;
  92.         * )               printf -v o '%%%02x' "'$c"
  93.      esac
  94.      encoded+="${o}"
  95.   done
  96.   echo "${encoded}"    # You can either set a return variable (FASTER)
  97.   REPLY="${encoded}"   #+or echo the result (EASIER)... or both... :p
  98. }
  99.  
  100. main $*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement