aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.md2
-rwxr-xr-xtimelog68
2 files changed, 62 insertions, 8 deletions
diff --git a/TODO.md b/TODO.md
index 8ab655d..08f2df2 100644
--- 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 140cad2..4dbbbc6 100755
--- a/timelog
+++ b/timelog
@@ -11,12 +11,22 @@
# 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