summaryrefslogtreecommitdiff
path: root/ar/.local/bin/task/taskwarrior-tui/increase-priority
blob: 26a3d539c9a1be2742a75c38fc699eb4e8d1af16 (plain)
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
55
56
57
58
59
60
#!/bin/sh

# The set -e option instructs the shell to immediately exit if any command has a non-zero exit status
# The set -u option treats unset variables (except for $* and $@) as an error
set -eu

echo "Increase duration of task $*"

# Fetch the duration value using taskwarrior and jq
dur=$(task "$@" export | jq -r '.[0].duration')

# Check if the duration has hours
case "$dur" in
*H*)
  # Extract both hour and minute parts
  hour=$(echo "$dur" | awk -F 'T' '{split($2, a, "H"); print a[1]}')
  minute=$(echo "$dur" | awk -F 'H' '{split($2, a, "M"); print a[1]}')

  # Add 30 to the minutes
  new_minute=$((minute + 30))

  # Check if minutes are 60 or more
  if [ "$new_minute" -ge 60 ]; then
    # Add 1 to the hour
    new_hour=$((hour + 1))

    # Calculate new minutes
    new_minute=$((new_minute - 60))
  else
    # Keep the original hour
    new_hour=$hour
  fi

  # Create the new duration string
  new_dur="PT${new_hour}H${new_minute}M"
  ;;
*)
  # If duration is already 30M
  if [ "$dur" = "PT30M" ]; then
    # Make it 1H
    new_dur="PT1H"
  else
    # Extract the minute part from the duration string
    minute=$(echo "$dur" | awk -F 'T' '{split($2, a, "M"); print a[1]}')

    # Add 30 to the minutes
    new_minute=$((minute + 30))

    # Create the new duration string
    new_dur="PT${new_minute}M"
  fi
  ;;
esac

# Print the new duration
echo "Original duration: $dur"
echo "New duration: $new_dur"

# Modify the task duration using taskwarrior
task rc.bulk=0 rc.confirmation=off rc.dependency.confirmation=off rc.recurrence.confirmation=off "$@" modify duration="$new_dur"