summaryrefslogtreecommitdiff
path: root/assets/ask.fish
blob: 46cb87de7cd86b74cab74774a580f1f5bf24fc8f (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Fish completion for ask.
# Install as ~/.config/fish/completions/ask.fish or $XDG_CONFIG_HOME/fish/completions/ask.fish.

function __ask_needs_root_completion
    set -l tokens (commandline -opc)
    if test (count $tokens) -le 1
        return 0
    end
    for token in $tokens[2..-1]
        if not string match -qr '^-' -- $token
            return 1
        end
    end
    return 0
end

function __ask_in_dep_context
    set -l tokens (commandline -opc)
    if test (count $tokens) -lt 2
        return 1
    end
    set -l seen_dep 0
    for token in $tokens[2..-1]
        if string match -qr '^-' -- $token
            continue
        end
        if test $seen_dep -eq 0
            if test $token = dep
                set seen_dep 1
            else
                return 1
            end
        else
            return 1
        end
    end
    test $seen_dep -eq 1
end

function __ask_in_uuid_context
    set -l tokens (commandline -opc)
    set -l positional
    for token in $tokens[2..-1]
        if string match -qr '^-' -- $token
            continue
        end
        set -a positional $token
    end
    if test (count $positional) -eq 0
        return 1
    end
    if test (count $positional) -gt 2
        return 1
    end
    switch $positional[1]
        case info annotate start stop done priority tag modify denotate delete
            return 0
        case '*'
            return 1
    end
    return 1
end

function __ask_in_dep_uuid_context
    set -l tokens (commandline -opc)
    set -l positional
    for token in $tokens[2..-1]
        if string match -qr '^-' -- $token
            continue
        end
        set -a positional $token
    end
    if test (count $positional) -lt 2
        return 1
    end
    if test $positional[1] != dep
        return 1
    end
    switch $positional[2]
        case add rm
            if test (count $positional) -le 4
                return 0
            end
        case list
            if test (count $positional) -le 3
                return 0
            end
        case '*'
            return 1
    end
    return 1
end

function __ask_task_uuids
    set -l now (date +%s)
    if set -q __ask_task_uuid_cache_until; and test $__ask_task_uuid_cache_until -ge $now
        printf '%s\n' $__ask_task_uuid_cache
        return 0
    end
    set -l uuids (command ask complete-uuids 2>/dev/null)
    if test $status -ne 0
        return 1
    end
    set -g __ask_task_uuid_cache $uuids
    set -g __ask_task_uuid_cache_until (math $now + 2)
    printf '%s\n' $uuids
end

complete -c ask -f
complete -c ask -s j -l json -d 'Emit JSON output'
complete -c ask -n '__ask_needs_root_completion' -a 'add' -d 'Create a new task'
complete -c ask -n '__ask_needs_root_completion' -a 'list' -d 'List active tasks'
complete -c ask -n '__ask_needs_root_completion' -a 'all' -d 'List all tasks'
complete -c ask -n '__ask_needs_root_completion' -a 'ready' -d 'List READY tasks'
complete -c ask -n '__ask_needs_root_completion' -a 'info' -d 'Show task details'
complete -c ask -n '__ask_needs_root_completion' -a 'annotate' -d 'Add an annotation'
complete -c ask -n '__ask_needs_root_completion' -a 'start' -d 'Start a task'
complete -c ask -n '__ask_needs_root_completion' -a 'stop' -d 'Stop a task'
complete -c ask -n '__ask_needs_root_completion' -a 'done' -d 'Mark a task complete'
complete -c ask -n '__ask_needs_root_completion' -a 'priority' -d 'Set priority'
complete -c ask -n '__ask_needs_root_completion' -a 'tag' -d 'Add or remove a tag'
complete -c ask -n '__ask_needs_root_completion' -a 'dep' -d 'Manage dependencies'
complete -c ask -n '__ask_needs_root_completion' -a 'urgency' -d 'List tasks sorted by urgency'
complete -c ask -n '__ask_needs_root_completion' -a 'modify' -d 'Modify task fields'
complete -c ask -n '__ask_needs_root_completion' -a 'denotate' -d 'Remove an annotation'
complete -c ask -n '__ask_needs_root_completion' -a 'delete' -d 'Delete a task'
complete -c ask -n '__ask_needs_root_completion' -a 'help' -d 'Show help'
complete -c ask -n '__ask_in_dep_context' -a 'add' -d 'Add a dependency'
complete -c ask -n '__ask_in_dep_context' -a 'rm' -d 'Remove a dependency'
complete -c ask -n '__ask_in_dep_context' -a 'list' -d 'List dependencies'
complete -c ask -n '__ask_in_uuid_context' -a '(__ask_task_uuids)' -d 'Task UUID'
complete -c ask -n '__ask_in_dep_uuid_context' -a '(__ask_task_uuids)' -d 'Task UUID'