From 2f5438dc21fab36ba973a9eafbeee3f0d3b81ce6 Mon Sep 17 00:00:00 2001 From: mitchell Date: Sat, 15 Aug 2020 19:06:43 -0400 Subject: [PATCH] Refactor push_tasks and add send_push,timetask functions --- .config/fish/functions/push_tasks.fish | 10 ++-------- .config/fish/functions/send_push.fish | 11 +++++++++++ .config/fish/functions/tasktime.fish | 9 +++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 .config/fish/functions/send_push.fish create mode 100644 .config/fish/functions/tasktime.fish diff --git a/.config/fish/functions/push_tasks.fish b/.config/fish/functions/push_tasks.fish index bfdd781..b21fd93 100644 --- a/.config/fish/functions/push_tasks.fish +++ b/.config/fish/functions/push_tasks.fish @@ -1,10 +1,4 @@ -function push_tasks -a token user -d 'Push tasks as a notification to your phone' +function push_tasks -d 'Push tasks as a notification to your phone' set tasks (task +READY export | jq 'sort_by(.urgency) | reverse | map(@text "\(.description)\nLink: \(.link)") | join("\n\n")') - set payload "{\"token\":\"$token\",\"user\":\"$user\",\"title\":\"Tasks\",\"message\":$tasks}" - - curl \ - -X POST \ - -H 'Content-Type: application/json' \ - -d $payload \ - https://api.pushover.net/1/messages.json + send_push $tasks end diff --git a/.config/fish/functions/send_push.fish b/.config/fish/functions/send_push.fish new file mode 100644 index 0000000..43863de --- /dev/null +++ b/.config/fish/functions/send_push.fish @@ -0,0 +1,11 @@ +function send_push -a message -d 'Send a push notification to your phone via pushover (optional delay as second arg)' + if test -n "$argv[2]"; sleep $argv[2]; end + + set payload "{\"token\":\"$pushover_token\",\"user\":\"$pushover_user\",\"title\":\"Tasks\",\"message\":$message}" + + curl \ + -X POST \ + -H 'Content-Type: application/json' \ + -d $payload \ + https://api.pushover.net/1/messages.json +end diff --git a/.config/fish/functions/tasktime.fish b/.config/fish/functions/tasktime.fish new file mode 100644 index 0000000..d995fd4 --- /dev/null +++ b/.config/fish/functions/tasktime.fish @@ -0,0 +1,9 @@ +function tasktime -a id time -d 'Set a time to check-in on task progress using pushover' + set half_time (math $time/2) + set desc (task _get $id.description) + + task $id start + + fish -c "send_push '\"Half-time: $desc\"' $half_time" > /dev/null & disown + fish -c "send_push '\"Timer over: $desc\"' $time" > /dev/null & disown +end