~tardypad/dotfiles

ref: 5fb618803953e3e2dc9f355ffc8bcecb6827f94d dotfiles/files/configs/zsh/functions/task-log -rw-r--r-- 894 bytes
5fb61880 — Damien Tardy-Panis Use local variables in task-log function 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
53
54
# 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 )"

local task id name desc duration

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}"