ソースを参照

Update how "day" script works

Samuel W. Flint 5 年 前
コミット
6495a1df0b
1 ファイル変更41 行追加8 行削除
  1. 41 8
      day

+ 41 - 8
day

@@ -2,17 +2,17 @@
 
 cd
 
-XSESS=1
+RESTART_I3=1
 
 SSH_TIME=${SSH_TIME:-3h}
 START_EMACS=${START_EMACS:-1}
 
 if [ -x "${DISPLAY}" ] ; then
-    XSESS=0
+    RESTART_I3=0
 fi
 
 if [ $# -lt 1 ] ; then
-    echo "$(basename $0) [ start | end | mid ]" >&2
+    echo "$(basename $0) [ start | end | mid ] [ -n ] [ -i ]" >&2
     exit 1
 fi
 
@@ -35,26 +35,59 @@ notify() {
 }
 
 restart_i3() {
-    if [ $XSESS -eq 1 ] ; then
+    if [ $RESTART_I3 -eq 1 ] ; then
         i3-msg restart
     fi
 }
 
-if [ $1 == "start" ] ; then
+help() {
+    cat <<EOF >&2
+$(basename $0) [ start | end | mid ] [ -n ] [ -i ]
+
+start :: Start the day
+end   :: End the day
+mid   :: Middle of the day Sync
+
+-n    :: Don't start Emacs
+-i    :: Don't restart i3
+EOF
+}
+
+CMD=$1
+shift
+
+while getopts nih opt
+do
+    case "$opt" in
+        n)
+            START_EMACS=0
+            ;;
+        i)
+            RESTART_I3=0
+            ;;
+        h)
+            help
+            exit 1
+            ;;
+    esac
+done
+
+
+if [ ${CMD} == "start" ] ; then
     check_ssh
     sync-dirs . School Projects
     restart_i3
     start_emacs
     notify "Starting Day" "On $(hostname -s)."
-elif [ $1 == "end" ] ; then
+elif [ ${CMD} == "end" ] ; then
     check_ssh
     sync-dirs . School Projects
     notify "Ending Day" "On $(hostname -s)."
-elif [ $1 == "mid" ] ; then
+elif [ ${CMD} == "mid" ] ; then
     check_ssh
     sync-dirs org .emacs.d School
     notify "Mid Day Sync" "On $(hostname -s)."
 else
-    echo "$(basename $0) [ start | end ]" >&2
+    help
     exit 1
 fi