]> gitweb.fluxo.info Git - timelog.git/commitdiff
Main menu support
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 24 Oct 2014 18:29:45 +0000 (16:29 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 24 Oct 2014 18:29:45 +0000 (16:29 -0200)
TODO.md
timelog

diff --git a/TODO.md b/TODO.md
index 8ab655d36fa3eef112b989755ec94ea48510f2d9..08f2df233fb61870fdb1400a71cbbe892571430a 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -1,4 +1,4 @@
 TODO
 ====
 
-* Nothing here? :P
+* Use `window_title` function from termplex if available.
diff --git a/timelog b/timelog
index 140cad29f41a3ff8c3bc5fb10f3c4a91d1822d4b..4dbbbc65015dc5165d88f9b02c077f417f8e95d4 100755 (executable)
--- a/timelog
+++ b/timelog
 # https://github.com/yaccz/worklog
 
 BASE="$HOME/file"
-CODEBASE="$HOME/code"
+CODE="$HOME/code"
 GROUP="$1"
 ACTION="$2"
 BASENAME="`basename $0`"
 EDITOR=${EDITOR:=vi}
 
+# Set window title
+# http://stackoverflow.com/questions/899609/gnu-screen-run-script-that-sends-commands-to-the-screen-session-it-is-being-run
+function timelog_window_title {
+  if [ -n "$STY" ]; then
+    screen -p $WINDOW -X title $1
+  else
+    xtitle $1
+  fi
+}
+
 # Setup a new worklog configuration
 function timelog_setup {
   cat > $BASE/$GROUP/worklog/projects <<EOF
@@ -34,16 +44,52 @@ EOF
 }
 
 # Loop over available worklogs
-# TODO
 function timelog_menu {
-  echo "Usage: $BASENAME <group> [edit]"
-  exit 1
+  # Basic variables
+  count=0
+  bases=(`find "$BASE" -maxdepth 2 -name worklog -exec dirname {} \;`)
+  codes=(`find "$CODE" -maxdepth 2 -name worklog -exec dirname {} \;`)
+  candidates=(${bases[@]} ${codes[@]})
+
+  # Clear the screen everytime we enter the menu
+  clear
+
+  # Draw menu and parse options
+  if [ ! -z "$candidates" ]; then
+    echo "Please select one of the following projects:"
+    echo ""
+
+    for candidate in ${candidates[@]}; do
+      echo -e "\t[$count] `basename $candidate`"
+      let count++
+    done
+
+    echo ""
+    read -p "Enter option (r to refresh, Ctrl-C or q to quit): " option
+
+    if [ "$option" == "q" ]; then
+      exit
+    elif [ "$option" == "r" ]; then
+      return
+    elif [[ "$option" =~ ^[0-9]+$ ]] && [ ! -z "${candidates[$option]}" ]; then
+      project="`basename ${candidates[$option]}`"
+      timelog $project
+    else
+      echo "Invalid option"
+      exit 1
+    fi
+  else
+    echo "Usage: $BASENAME <group> [edit]"
+    exit 1
+  fi
 }
 
 # Run
 function timelog_run {
-  if [ -d "$CODEBASE/$GROUP" ] && [ ! -d "$BASE/$GROUP" ]; then
-    BASE="$CODEBASE"
+  timelog_window_title "log: $GROUP"
+
+  if [ -d "$CODE/$GROUP" ] && [ ! -d "$BASE/$GROUP" ]; then
+    BASE="$CODE"
   fi
 
   mkdir -p $BASE/$GROUP/worklog
@@ -61,5 +107,13 @@ function timelog_run {
 if [ ! -z "$GROUP" ]; then
   timelog_run
 else
-  timelog_menu
+  while true; do
+    # Set window title
+    timelog_window_title "log"
+
+    timelog_menu
+  done
 fi
+
+# Restore screen title
+window_title terminal