all repos — scriptura @ 319bfc4b41d00530088721134a067d172de8bd3a

a corner in $HOME for your scripts

rework completion functions - read root from environment - enable testing by preferring argv over $(commandline -xpc)

Alan Pearce
commit

319bfc4b41d00530088721134a067d172de8bd3a

parent

67c5dc65972ef72d72080ea7792296971c8f388c

M completions/scriptura.fishcompletions/scriptura.fish
@@ -3,40 +3,40 @@
complete --command scriptura --no-files complete --command scriptura \ - --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \ + --condition 'not __fish_seen_subcommand_from $(__scriptura_subcommands)' \ --short-option h --long-option help \ --description 'Display help information' complete --command scriptura \ - --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \ + --condition 'not __fish_seen_subcommand_from $(__scriptura_subcommands)' \ --short-option n --long-option new \ --description 'Create new script' complete --command scriptura \ - --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \ + --condition 'not __fish_seen_subcommand_from $(__scriptura_subcommands)' \ --short-option e --long-option edit \ --description 'Edit existing script' complete --command scriptura \ - --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \ + --condition 'not __fish_seen_subcommand_from $(__scriptura_subcommands)' \ --short-option c --long-option cat \ --description 'Display script content' complete --command scriptura \ - --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SCRIPTURA_ROOT)' \ + --condition 'not __fish_seen_subcommand_from $(__scriptura_subcommands)' \ --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)' + --condition 'not __fish_seen_subcommand_from $(__scriptura_subcommands)' \ + --arguments '(__scriptura_complete_script)' 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))' + --condition '__fish_seen_subcommand_from $(__scriptura_subcommands)' \ + --condition 'not __scriptura_seen_script' \ + --arguments '(__scriptura_complete_script)' complete --command scriptura \ - --condition '__scriptura_seen_script $(commandline -xpc)' \ + --condition __scriptura_seen_script \ --force-files
D functions/__scriptura_complete.fish
@@ -1,10 +0,0 @@
-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_complete_script.fish
@@ -0,0 +1,19 @@
+function __scriptura_complete_script + set --function from $SCRIPTURA_ROOT + + test (count $argv) -ne 0 + or set --function argv (commandline -xpc)[2..] + + for arg in $argv + if path is --type dir $from/$arg + set --function from $from/$arg + else if path is --type file $from/$arg + return + end + end + + set --function types file,dir + for entry in $(path filter --type $types --perm exec $from/*) + printf "%s\t%s\n" $(path basename $entry) $(__scriptura_help $entry) + end +end
D functions/__scriptura_print.fish
@@ -1,3 +0,0 @@
-function __scriptura_print --argument-names from - path basename $(path filter --type file,dir --perm exec $from/*) -end
M functions/__scriptura_seen_script.fishfunctions/__scriptura_seen_script.fish
@@ -1,17 +1,19 @@
function __scriptura_seen_script - set --function argv $argv[2..-1] + test (count $argv) -ne 0 + or set --function argv (commandline -xpc)[2..] + 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]" = -- + for arg in $argv + if test "$arg" = -- 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] + else if path is --type dir $target/$arg + set --function target $target/$arg + else if path is --type file --perm exec $target/$arg return 0 else break
A functions/__scriptura_subcommands.fish
@@ -0,0 +1,3 @@
+function __scriptura_subcommands + path basename $(path filter --type file,dir --perm exec $SCRIPTURA_ROOT/*) +end