day 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/sh
  2. cd
  3. RESTART_I3=1
  4. SSH_TIME=${SSH_TIME:-3h}
  5. START_EMACS=${START_EMACS:-1}
  6. if [ -x "${DISPLAY}" ] ; then
  7. RESTART_I3=0
  8. fi
  9. if [ $# -lt 1 ] ; then
  10. echo "$(basename $0) [ start | end | mid ] [ -n ] [ -i ]" >&2
  11. exit 1
  12. fi
  13. check_ssh() {
  14. ssh-add -l >/dev/null
  15. SSH_ADDED=$?
  16. if [ $SSH_ADDED != 0 ] ; then
  17. ssh-add -t ${SSH_TIME}
  18. fi
  19. }
  20. start_emacs() {
  21. if [ $START_EMACS -eq 1 ] ; then
  22. i3-run i3-workspace-layout emacs-here '"1: emacs"'
  23. fi
  24. }
  25. notify() {
  26. send-notification "$1" "$2"
  27. }
  28. restart_i3() {
  29. if [ $RESTART_I3 -eq 1 ] ; then
  30. i3-msg restart
  31. fi
  32. }
  33. rsync_between() {
  34. LOCAL=$1
  35. REMOTE=$2
  36. rsync -aPuzb "$REMOTE" "$LOCAL"
  37. rsync -aPuzb --exclude=.git/ "$LOCAL" "$REMOTE"
  38. }
  39. rsync_directories() {
  40. rsync_between ~/News/ swflint@boole.flintfam.org:News/
  41. rsync_between ~/Mail/ swflint@boole.flintfam.org:Mail/
  42. rsync_between ~/.elfeed/ swflint@boole.flintfam.org:Elfeed/
  43. }
  44. help() {
  45. cat <<EOF >&2
  46. $(basename $0) [ start | end | mid ] [ -n ] [ -i ]
  47. start :: Start the day
  48. end :: End the day
  49. mid :: Middle of the day Sync
  50. -n :: Don't start Emacs
  51. -i :: Don't restart i3
  52. EOF
  53. }
  54. CMD=$1
  55. shift
  56. while getopts nih opt
  57. do
  58. case "$opt" in
  59. n)
  60. START_EMACS=0
  61. ;;
  62. i)
  63. RESTART_I3=0
  64. ;;
  65. h)
  66. help
  67. exit 1
  68. ;;
  69. esac
  70. done
  71. if [ ${CMD} == "start" ] ; then
  72. check_ssh
  73. sync-dirs ~ School Projects
  74. rsync_directories
  75. restart_i3
  76. start_emacs
  77. notify "Starting Day" "On $(hostname -s)."
  78. elif [ ${CMD} == "end" ] ; then
  79. check_ssh
  80. sync-dirs ~ School Projects
  81. rsync_directories
  82. notify "Ending Day" "On $(hostname -s)."
  83. elif [ ${CMD} == "mid" ] ; then
  84. check_ssh
  85. sync-dirs org .emacs.d EBooks Documents School .ledger
  86. rsync_directories
  87. notify "Mid Day Sync" "On $(hostname -s)."
  88. else
  89. help
  90. exit 1
  91. fi