2020-12-06 10:05:30 +01:00
|
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
|
|
# From Kehet
|
|
|
|
|
## https://gist.github.com/Kehet/5ba8a530e52ea3a0ae251d756faef680
|
|
|
|
|
|
2021-10-06 17:52:38 +02:00
|
|
|
|
# Vars {{{
|
|
|
|
|
## Current tasks temp file
|
|
|
|
|
readonly TASKW_CURRENT_LIST="/tmp/rofi-task.sh-current.tasks"
|
|
|
|
|
|
|
|
|
|
## Rofi colors
|
2020-12-06 10:05:30 +01:00
|
|
|
|
black="#000000"
|
|
|
|
|
blue="#0094cc"
|
2021-10-06 17:52:38 +02:00
|
|
|
|
# }}}
|
2020-12-06 10:05:30 +01:00
|
|
|
|
|
2021-10-06 17:07:38 +02:00
|
|
|
|
is_task_running() { # {{{
|
2020-12-06 10:05:30 +01:00
|
|
|
|
|
2021-10-06 17:07:38 +02:00
|
|
|
|
if task active >/dev/null 2>&1; then
|
|
|
|
|
return_is_task_running="0"
|
|
|
|
|
else
|
|
|
|
|
return_is_task_running="1"
|
|
|
|
|
fi
|
2020-12-06 10:05:30 +01:00
|
|
|
|
|
2021-10-06 17:07:38 +02:00
|
|
|
|
return "${return_is_task_running:=/dev/null}"
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
display_current_task() { # {{{
|
|
|
|
|
|
2021-10-06 17:52:38 +02:00
|
|
|
|
## List active task(s) in a temp file
|
|
|
|
|
touch -- "${TASKW_CURRENT_LIST}"
|
|
|
|
|
printf '%b\n\n' " Choose a task to STOP" >> "${TASKW_CURRENT_LIST}"
|
|
|
|
|
task +ACTIVE export | jq -r 'sort_by( -.urgency )[] | [ (.id|tostring), .description ] | join(" ")' >> "${TASKW_CURRENT_LIST}"
|
|
|
|
|
|
2021-10-06 17:07:38 +02:00
|
|
|
|
## Display active tasks list and get title from the choosen one
|
2021-10-06 17:52:38 +02:00
|
|
|
|
TITLE=$(rofi -location 2 -lines 5 -no-auto-select -i -dmenu -p "RUNNING task(s)" -color-enabled -color-normal "${blue},${black},${blue},${black},${blue}" -color-window "${blue},${blue}" < "${TASKW_CURRENT_LIST}" |
|
2021-11-16 10:02:21 +01:00
|
|
|
|
cut --delimiter=" " --field=2 |
|
|
|
|
|
sed "s/[0-9]//g")
|
2021-10-13 10:53:39 +02:00
|
|
|
|
ID=$(task "${TITLE}" simpleid | grep --after-context=2 -- ID | tail --lines=1 || return 0)
|
2021-10-06 17:07:38 +02:00
|
|
|
|
|
2021-10-06 17:52:38 +02:00
|
|
|
|
## Remove temp file
|
|
|
|
|
rm --force -- "${TASKW_CURRENT_LIST}"
|
|
|
|
|
|
|
|
|
|
## If no task was selected (empty var) then exit
|
|
|
|
|
[ -z "${TITLE}" ] && echo "Cancelled." && exit 0
|
|
|
|
|
|
2021-10-13 10:53:39 +02:00
|
|
|
|
## If no ID was found (empty var) then exit
|
|
|
|
|
[ -z "${ID}" ] && echo "Cancelled." && exit 0
|
|
|
|
|
|
2021-10-12 09:46:47 +02:00
|
|
|
|
## Kill any pomodorrior process running for the current task
|
|
|
|
|
pkill --full -- "${TITLE}"
|
|
|
|
|
|
|
|
|
|
## Also kill any "sleep 60" remaining process
|
|
|
|
|
pkill --full -- "sleep 60"
|
|
|
|
|
|
2021-10-06 17:52:38 +02:00
|
|
|
|
## Stop the selected task and exit
|
2021-10-13 10:53:39 +02:00
|
|
|
|
task "${ID}" stop >/dev/null && exit 0
|
2021-10-06 17:07:38 +02:00
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
select_task() { # {{{
|
|
|
|
|
## Display pending tasks list and get title from the choosen one
|
2021-10-12 09:33:42 +02:00
|
|
|
|
TITLE=$(task status:pending export | jq -r 'sort_by( -.urgency )[] | [ (.id|tostring), .description ] | join(" ")' | sort --numeric-sort --reverse |
|
2021-10-06 17:07:38 +02:00
|
|
|
|
rofi -location 2 -no-auto-select -i -dmenu -p "Task" -color-enabled -color-normal "${black},${blue},${black},${blue},${black}" -color-window "${black},${black}" |
|
|
|
|
|
cut --delimiter=" " --field=2)
|
|
|
|
|
|
|
|
|
|
[ -z "${TITLE}" ] && echo "Cancelled." && exit 0
|
|
|
|
|
|
|
|
|
|
## Start task with pomodorrior script (task end after 25 minutes)
|
|
|
|
|
pomodorrior "${TITLE}" && exit 0
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
main() { # {{{
|
|
|
|
|
|
|
|
|
|
is_task_running \
|
|
|
|
|
&& display_current_task \
|
|
|
|
|
&& exit 0
|
|
|
|
|
|
|
|
|
|
select_task \
|
|
|
|
|
&& exit 0
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
main
|
2020-12-06 10:05:30 +01:00
|
|
|
|
|
|
|
|
|
exit 255
|