all repos — scriptura @ c45b4ea656064fa445843ab7885f814350232446

a corner in $HOME for your scripts

completions/scriptura.fish (view raw)

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
set --query SCRIPTURA_ROOT or set --local SCRIPTURA_ROOT "~/sd"

complete --command scriptura --no-files

complete --command scriptura \
    --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \
    --short-option h --long-option help \
    --description 'Display help information'

complete --command scriptura \
    --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \
    --short-option n --long-option new \
    --description 'Create new script'

complete --command scriptura \
    --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \
    --short-option e --long-option edit \
    --description 'Edit existing script'

complete --command scriptura \
    --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \
    --short-option c --long-option cat \
    --description 'Display script content'

complete --command scriptura \
    --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \
    --short-option w --long-option which \
    --description 'Display script path'

complete --command scriptura \
    --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \
    --arguments '$(__scriptura_complete $SCRIPTURA_ROOT)'

complete --command scriptura \
    --condition '__fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \
    --condition 'not __scriptura_seen_script $(commandline -xpc)' \
    --condition 'not __fish_seen_argument --short n --long new' \
    --arguments '$(__scriptura_complete $SCRIPTURA_ROOT $(commandline -xpc))'

complete --command scriptura \
    --condition '__scriptura_seen_script $(commandline -xpc)' \
    --force-files

function __scriptura_print --argument-names from
    path basename $(path filter --type file,dir --perm exec $from/*)
end

function __scriptura_complete --argument-names from
    for arg in $argv[2..-1]
        if path is --type dir $from/$arg
            set --function from $from/$arg
        end
    end
    for entry in $(path filter --type file,dir --perm exec $from/*)
        printf "%s\t%s\n" $(path basename $entry) $(__scriptura_help $entry)
    end
end

function __scriptura_seen_script
    set --function argv $argv[2..-1]
    set --function target $SCRIPTURA_ROOT

    if not set --query argv[1]
        return 1
    end

    for i in (seq 1 (count $argv))
        if test "$argv[$i]" = --
            break
        else if path is --type dir $target/$argv[$i]
            set --function target $target/$argv[$i]
        else if path is --type file --perm exec $target/$argv[$i]
            return 0
        else
            break
        end
    end

    return 1
end