~tardypad/dotfiles

ref: b05d2c44bacbdda1a7a05ab02fbac002eaf5abd9 dotfiles/files/configs/zsh/functions/task-log -rw-r--r-- 860 bytes
b05d2c44 — Damien Tardy-Panis Allow logging of a task on a given day 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# commands used:
# - fzf
# - task
# - time-tracker

# 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 \
          --no-multi \
          --info hidden \
          --header "$( printf '\n' )" \
          --prompt 'log task ' \
    | tail -n1
)

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

ID="$( echo "${TASK}" | cut -f1 )"
NAME="$( echo "${TASK}" | cut -f2 )"

printf 'Id: %s\n' "${ID}"

if [ -n "${NAME}" ]; then
  printf 'Name: %s\n' "${NAME}"
fi

printf 'Description: '
read -r DESC

while true; do
  printf 'Duration (min): '
  read -r DURATION

  case "${DURATION}" in
    *[!0-9]*)
      echo 'duration must be an integer' >&2
      continue
      ;;
  esac

  break
done

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

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