2ck

JJ

2ck
Feb 27th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.04 KB | None | 0 0
  1. #!/bin/sh
  2. # Journal writing script
  3. # creates a journal underneath ~/journal (initialise yourself)
  4. # with year/month/entry
  5. # Copyright (c) 2012 2ck
  6.  
  7. cd ~/journal
  8.  
  9. year=`date +%Y`
  10. month=`date +%m`
  11. day=`date +%d`
  12.  
  13. if [ ! -e $year ] ; then
  14.     mkdir $year || exit 1
  15. fi
  16. cd $year
  17.  
  18. if [ ! -e $month ] ; then
  19.     mkdir $month || exit 1
  20. fi
  21. cd $month
  22.  
  23. if [ -e $day ] ; then
  24.     echo "You already have an entry for today."
  25.     echo "Do you want to (r)eplace it or write an (u)pdate?"
  26.     read ans
  27.     case $ans in
  28.         u|U)
  29.             day=$day-`echo $day* | wc -w`
  30.             ;;
  31.         r|R)
  32.             rm $day
  33.             ;;
  34.           *)
  35.             echo "Okay, whatever." ; exit 2
  36.             ;;
  37.     esac
  38. fi
  39. date +%H.%M | cat > "dt"
  40. for title
  41. do
  42.     echo $title | tr '[a-z]' '[A-Z]' | cat >> "dt"
  43. done
  44. echo "$title " | sed s/./-/g | cat >> "dt"
  45. touch $day
  46.  
  47. vim -c "read dt" -c "set wrap" -c 'startinsert' + $day
  48.  
  49. rm dt
  50. if [ ! -s $day ] ; then
  51.     rm -v $day
  52. fi
  53. if [ -e .$day.swp ] ; then
  54.     rm -v .$day.swp
  55. fi
Advertisement
Add Comment
Please, Sign In to add comment