extract completion helper functions
4 files changed, 35 insertions(+), 38 deletions(-)
M completions/scriptura.fish → completions/scriptura.fish
@@ -40,41 +40,3 @@ 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
A functions/__scriptura_complete.fish
@@ -0,0 +1,10 @@ +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
A functions/__scriptura_print.fish
@@ -0,0 +1,3 @@ +function __scriptura_print --argument-names from + path basename $(path filter --type file,dir --perm exec $from/*) +end
A functions/__scriptura_seen_script.fish
@@ -0,0 +1,22 @@ +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