summaryrefslogtreecommitdiff
path: root/scripts/deploy/completions/fish.fish
blob: 29044955ee0f4edddecb6805571f48f5c196287c (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
#!/usr/bin/env fish
function __jvn_fish_complete
    set -l cmdline (commandline -opc)
    set -l buffer (commandline -b)
    set -l cursor (commandline -C)

    set -l current_word ""
    set -l previous_word ""
    set -l word_index 0
    set -l char_count 0

    for i in (seq (count $cmdline))
        set word $cmdline[$i]
        set char_count (math $char_count + (string length "$word") + 1)

        if test $cursor -le $char_count
            set word_index $i
            set current_word $word
            if test $i -gt 1
                set previous_word $cmdline[(math $i - 1)]
            end
            break
        end
    end

    set -l args \
        -f "$buffer" \
        -C "$cursor" \
        -w "$current_word" \
        -p "$previous_word" \
        -c "$cmdline[1]" \
        -i "$word_index" \
        -a $cmdline

    set -l output (jvn_comp $args 2>/dev/null)
    if test "$output" = "_file_"
        __fish_complete_path "$current_word"
    else
        printf "%s\n" $output
    end
end

complete -c jvn -a '(__jvn_fish_complete)'