Compare commits
No commits in common. "17159d0fa283d54ff4f389974fa4758ac49e0b5b" and "e562e3680f1afdff02ce2d9b18819d7758f097fb" have entirely different histories.
17159d0fa2
...
e562e3680f
3 changed files with 32 additions and 119 deletions
12
bin/git-pick
12
bin/git-pick
|
@ -4,18 +4,8 @@ mkdir -p "$(git rev-parse --git-dir)/fzf"
|
||||||
history="$(git rev-parse --git-dir)/fzf/history"
|
history="$(git rev-parse --git-dir)/fzf/history"
|
||||||
null=$(printf "\0")
|
null=$(printf "\0")
|
||||||
|
|
||||||
untracked='/^?? /d'
|
|
||||||
|
|
||||||
while test $# != 0
|
|
||||||
do
|
|
||||||
case "$1" in
|
|
||||||
(--untracked | -u) untracked="" ;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
IFS=''
|
IFS=''
|
||||||
git status --porcelain | sed "$untracked" | while read line
|
git status --porcelain | while read line
|
||||||
do
|
do
|
||||||
path=$(echo $line | cut -b 4-)
|
path=$(echo $line | cut -b 4-)
|
||||||
type=$(echo $line | cut -b -3)
|
type=$(echo $line | cut -b -3)
|
||||||
|
|
105
bin/tasknotif
105
bin/tasknotif
|
@ -3,89 +3,31 @@
|
||||||
local json = require "cjson"
|
local json = require "cjson"
|
||||||
local arrr = require "arrr"
|
local arrr = require "arrr"
|
||||||
local shapeshift = require "shapeshift"
|
local shapeshift = require "shapeshift"
|
||||||
local lumber = require("lumber")
|
|
||||||
|
|
||||||
local log = lumber.new {
|
|
||||||
level = lumber.levels.WARN;
|
|
||||||
format = require "lumber.format.term";
|
|
||||||
filter = function(message)
|
|
||||||
if type(message) == "string" then
|
|
||||||
return message
|
|
||||||
else
|
|
||||||
return require("inspect")(message)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
local default_config = {
|
|
||||||
{ notify = "zenity", minutes = 60 };
|
|
||||||
{ notify = "notify", minutes = 180 };
|
|
||||||
}
|
|
||||||
|
|
||||||
local function zulu_offset()
|
local function zulu_offset()
|
||||||
local current = os.date("*t")
|
local current = os.date("*t")
|
||||||
current.isdst = false
|
current.isdst = false
|
||||||
local zulu = os.date("!*t")
|
local zulu = os.date("!*t")
|
||||||
--- @cast zulu -string
|
|
||||||
--- @cast current -string
|
|
||||||
return os.difftime(os.time(current), os.time(zulu))
|
return os.difftime(os.time(current), os.time(zulu))
|
||||||
end
|
end
|
||||||
|
|
||||||
local config_file do
|
|
||||||
local xdg_home = os.getenv("XDG_CONFIG_HOME")
|
|
||||||
local home = os.getenv("HOME")
|
|
||||||
if xdg_home then
|
|
||||||
config_file = xdg_home .. "/task/tasknotif.lua"
|
|
||||||
elseif home then
|
|
||||||
config_file = home .. "/.config/task/tasknotif.lua"
|
|
||||||
else
|
|
||||||
config_file = "tasknotif.lua"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local params do
|
local params do
|
||||||
local parse = arrr {
|
local parse = arrr {
|
||||||
{ "Configuration to use (default: "..config_file..")", "--config", "-c" };
|
{ "Time or something", "--minutes", "-m", "number" };
|
||||||
{ "Sets the log level", "--log", nil, true };
|
{ "Use Zenity to display a window instead of sending a notification", "--zenity", "-z" }
|
||||||
{ "Ignore anything that's already due soon at program start", "--pre-check" };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local validate = shapeshift.table {
|
local validate = shapeshift.table {
|
||||||
__extra = "keep";
|
__extra = "keep";
|
||||||
precheck = shapeshift.default(false, shapeshift.is.boolean);
|
minutes = shapeshift.default(30, shapeshift.is.number);
|
||||||
}
|
}
|
||||||
|
|
||||||
params = select(2, validate(parse(arg)))
|
params = select(2, validate(parse(arg)))
|
||||||
end
|
end
|
||||||
|
|
||||||
if params.log then
|
|
||||||
log.level = lumber.levels[string.upper(params.log)]
|
|
||||||
end
|
|
||||||
|
|
||||||
log:debug("Params", params)
|
|
||||||
|
|
||||||
log:info "Starting taskwarrior notifier"
|
|
||||||
|
|
||||||
--- @type table
|
|
||||||
local config if params.config then
|
|
||||||
config = assert(loadfile(params.config))()
|
|
||||||
else
|
|
||||||
local chunk = loadfile(config_file)
|
|
||||||
config = chunk and chunk() or default_config
|
|
||||||
end
|
|
||||||
|
|
||||||
local done = {}
|
local done = {}
|
||||||
for severity in ipairs(config) do
|
|
||||||
done[severity] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @param run boolean Whether there should be any notification at all
|
while true do
|
||||||
local function check(run)
|
|
||||||
-- Save handled tasks in the current loop so the same task doesn't get several notififations at once
|
|
||||||
local handled = {}
|
|
||||||
if run == nil then run = true end
|
|
||||||
for severity, condition in ipairs(config) do
|
|
||||||
log:debug(condition)
|
|
||||||
local data = json.decode(io.popen("task export"):read("*a"))
|
local data = json.decode(io.popen("task export"):read("*a"))
|
||||||
for _, task in ipairs(data) do
|
for _, task in ipairs(data) do
|
||||||
if task.status == "pending" and task.due then
|
if task.status == "pending" and task.due then
|
||||||
|
@ -99,46 +41,27 @@ local function check(run)
|
||||||
|
|
||||||
-- If anything gets postponed outside of the warning time,
|
-- If anything gets postponed outside of the warning time,
|
||||||
-- remove it from the done list
|
-- remove it from the done list
|
||||||
if done[severity][task.uuid] then
|
if done[task.uuid] then
|
||||||
if os.difftime(task.due, os.time()) > 60 * condition.minutes then
|
if os.difftime(task.due, os.time()) > 60*params.minutes then
|
||||||
done[severity][task.uuid] = nil
|
done[task.uuid] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if os.difftime(task.due, os.time()) < 60 * condition.minutes then
|
if os.difftime(task.due, os.time()) < 60*params.minutes then
|
||||||
if handled[task.uuid] then
|
if not done[task.uuid] then
|
||||||
log:info("Skipping task "..task.uuid..": already handled in this loop")
|
done[task.uuid] = task
|
||||||
end
|
print("Notifying:", task.uuid, task.description)
|
||||||
if not done[severity][task.uuid] then
|
if params.zenity then
|
||||||
done[severity][task.uuid] = task
|
|
||||||
if run and not handled[task.uuid] then
|
|
||||||
log:info("Notifying:", task.uuid, task.description)
|
|
||||||
if condition.notify == "zenity" then
|
|
||||||
os.execute(string.format("zenity --warning --title '%s' --text '%s'", "Task due soon", task.description))
|
os.execute(string.format("zenity --warning --title '%s' --text '%s'", "Task due soon", task.description))
|
||||||
elseif condition.notify == "notify" then
|
|
||||||
os.execute("notify-send 'Task due soon' '"..task.description:gsub([[']], [['"'"']]).."'")
|
|
||||||
else
|
else
|
||||||
error("Unknown notification type: " .. tostring(condition.notify))
|
os.execute("notify-send 'Task due soon' '"..task.description:gsub([[']], [['"'"']]).."'")
|
||||||
end
|
|
||||||
handled[task.uuid] = task
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if params.precheck then
|
if not os.execute("sleep 5") then
|
||||||
log:info "Doing initial pre-scan"
|
|
||||||
check(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
log:info "Starting scan loop"
|
|
||||||
while true do
|
|
||||||
check(true)
|
|
||||||
if not os.execute("sleep 30") then
|
|
||||||
log:info "Exiting taskwarrior notifier"
|
|
||||||
os.exit()
|
os.exit()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
dog = log --decorate --oneline --graph --date-order
|
dog = log --decorate --oneline --graph --date-order
|
||||||
fadd = "! git pick | xargs --open-tty git add"
|
fadd = "! git pick | xargs --open-tty git add"
|
||||||
fig = "! git pick | xargs -L1 git ignore"
|
fig = "! git pick | xargs -L1 git ignore"
|
||||||
faddall = "! git pick --untracked | xargs --open-tty git add"
|
faddall = "! git status --porcelain | cut -b 4- | fzf --multi --layout=reverse-list | xargs --open-tty git add"
|
||||||
fixup = "!git commit --patch --no-edit --amend $(git diff --name-only HEAD~1..HEAD)"
|
fixup = "!git commit --patch --no-edit --amend $(git diff --name-only HEAD~1..HEAD)"
|
||||||
h = log -1 --format=%h
|
h = log -1 --format=%h
|
||||||
hash = log -1 --format=%H
|
hash = log -1 --format=%H
|
||||||
|
|
Loading…
Reference in a new issue