day 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. help() {
  34. cat <<EOF >&2
  35. $(basename $0) [ start | end | mid ] [ -n ] [ -i ]
  36. start :: Start the day
  37. end :: End the day
  38. mid :: Middle of the day Sync
  39. -n :: Don't start Emacs
  40. -i :: Don't restart i3
  41. EOF
  42. }
  43. CMD=$1
  44. shift
  45. while getopts nih opt
  46. do
  47. case "$opt" in
  48. n)
  49. START_EMACS=0
  50. ;;
  51. i)
  52. RESTART_I3=0
  53. ;;
  54. h)
  55. help
  56. exit 1
  57. ;;
  58. esac
  59. done
  60. if [ ${CMD} == "start" ] ; then
  61. check_ssh
  62. sync-dirs . School Projects
  63. restart_i3
  64. start_emacs
  65. notify "Starting Day" "On $(hostname -s)."
  66. elif [ ${CMD} == "end" ] ; then
  67. check_ssh
  68. sync-dirs . School Projects
  69. notify "Ending Day" "On $(hostname -s)."
  70. elif [ ${CMD} == "mid" ] ; then
  71. check_ssh
  72. sync-dirs org .emacs.d EBooks Documents School .ledger
  73. notify "Mid Day Sync" "On $(hostname -s)."
  74. else
  75. help
  76. exit 1
  77. fi