~tardypad/dotfiles

b05d2c44bacbdda1a7a05ab02fbac002eaf5abd9 — Damien Tardy-Panis 3 months ago f37f64d
Allow logging of a task on a given day
M files/configs/zsh/Makefile => files/configs/zsh/Makefile +1 -0
@@ 37,6 37,7 @@ zsh-configs:
	$(setup_file)/configs/zsh/completions/_somafm                                                    > $(DESTDIR)$(HOME)/.zsh/completions/_somafm
	$(setup_file)/configs/zsh/completions/_ssh-tags                                                  > $(DESTDIR)$(HOME)/.zsh/completions/_ssh-tags
	$(setup_file)/configs/zsh/completions/_task                                                      > $(DESTDIR)$(HOME)/.zsh/completions/_task
	$(setup_file)/configs/zsh/completions/_task-log                                                  > $(DESTDIR)$(HOME)/.zsh/completions/_task-log
	$(setup_file)/configs/zsh/completions/_time-tracker                                              > $(DESTDIR)$(HOME)/.zsh/completions/_time-tracker
	$(setup_file)/configs/zsh/completions/_time-tracker-sum                                          > $(DESTDIR)$(HOME)/.zsh/completions/_time-tracker-sum
	$(setup_file)/configs/zsh/completions/_tmux-env                                                  > $(DESTDIR)$(HOME)/.zsh/completions/_tmux-env

A files/configs/zsh/completions/_task-log => files/configs/zsh/completions/_task-log +10 -0
@@ 0,0 1,10 @@
#compdef task-log

local logging_dir="${XDG_DATA_HOME:-$HOME/.local/share}/time-tracker/logs"

_days() {
  _path_files -W "${logging_dir}"
}

_arguments \
  '1:day:_days'

M files/configs/zsh/completions/_time-tracker => files/configs/zsh/completions/_time-tracker +1 -1
@@ 27,7 27,7 @@ _operands() {
}

_arguments \
  '-d[logging day]:day:_days' \
  '-g[display logs grouped by identifier]' \
  '-t[display logs with values separated by tab]' \
  '1:action:_actions' \
  '2:operand:_operands'

M files/configs/zsh/functions/task-log => files/configs/zsh/functions/task-log +5 -1
@@ 5,6 5,10 @@

# select a task and log it for the current day

local day="$1"

[ -n "${day}" ] || day="$( date +%Y-%m-%d )"

TASK=$(
  task -n ids \
    | fzf --reverse \


@@ 45,4 49,4 @@ done

[ -n "${DURATION}" ] || return

time-tracker log "${ID}" "${DURATION}" "${DESC}"
time-tracker -d "${day}" log "${ID}" "${DURATION}" "${DESC}"

M files/docs/shell/time-tracker.scd => files/docs/shell/time-tracker.scd +6 -3
@@ 10,11 10,11 @@ time-tracker *start* _id_ [ _description_ ]

time-tracker [ *show* | *stop* ]

time-tracker *log* _id_ _duration_ [ _description_ ]
time-tracker [-d _day_] *log* _id_ _duration_ [ _description_ ]

time-tracker [-gt] *overview* [ _day_ ]
time-tracker [-gt] [-d _day_] *overview*

time-tracker *edit* [ _day_ ]
time-tracker [-d _day_] *edit*

# DESCRIPTION



@@ 22,6 22,9 @@ Track and log the time spent on a task

# OPTIONS

*-d* _day_
	Logging day to use for the action

*-g*
	Display logs grouped by identifier with durations summed


M files/scripts/shell/time-tracker => files/scripts/shell/time-tracker +3 -6
@@ 16,8 16,9 @@ init_variables() {
}

parse_command_line() {
  while getopts gt OPT; do
  while getopts d:gt OPT; do
    case "${OPT}" in
      d) LOGGING_DAY="${OPTARG}" ;;
      g) GROUPED_DISPLAY=true ;;
      t) TAB_SEPARATED=true ;;
      ?) exit_error ;;


@@ 35,8 36,6 @@ parse_command_line() {
    TASK_ID="$2"
    TASK_DURATION="$3"
    TASK_DESC="$4"
  elif [ "${ACTION}" = 'edit' ] || [ "${ACTION}" = 'overview' ]; then
    [ -z "$2" ] || LOGGING_DAY="$2"
  fi
}



@@ 139,11 138,9 @@ is_tracking_task() {

time_tracker_log()
{
  CURRENT_DAY=$( date +%Y-%m-%d )

  printf '%s\t%s\t%s\n' \
    "${TASK_ID}" "${TASK_DURATION}" "${TASK_DESC}" \
    >> "${LOGGING_DIR}/${CURRENT_DAY}"
    >> "${LOGGING_DIR}/${LOGGING_DAY}"
}

time_tracker_edit()