add command completion to --new (after --)
4 files changed, 34 insertions(+), 1 deletion(-)
M completions/scriptura.fish → completions/scriptura.fish
@@ -32,11 +32,21 @@ --condition 'not __fish_seen_subcommand_from $(__scriptura_subcommands)' \ --arguments '(__scriptura_complete_script)' complete --command scriptura \ - --condition 'not __fish_seen_argument --short n --long new' \ --condition '__fish_seen_subcommand_from $(__scriptura_subcommands)' \ --condition 'not __scriptura_seen_script' \ --arguments '(__scriptura_complete_script)' complete --command scriptura \ --condition __scriptura_seen_script \ + --condition 'not contains -- "--" (commandline -xpc)' \ + --arguments -- + +complete --command scriptura \ + --condition __scriptura_seen_script \ + --condition 'contains -- "--" (commandline -xpc)' \ --force-files + +complete --command scriptura \ + --condition '__fish_seen_argument --short n --long new' \ + --condition __scriptura_seen_script \ + --arguments '(__scriptura_complete_new)'
A functions/__scriptura_complete_new.fish
@@ -0,0 +1,11 @@ +function __scriptura_complete_new + test (count $argv) -ne 0 + or set --function argv (commandline -xpc)[2..] (commandline -ct) + + set --function index (contains --index -- "--" $argv) + or return + + set --function remaining $argv[(math $index + 1)..] + + __fish_complete_subcommand --commandline $remaining +end
M functions/__scriptura_complete_script.fish → functions/__scriptura_complete_script.fish
@@ -4,6 +4,8 @@ test (count $argv) -ne 0 or set --function argv (commandline -xpc)[2..] + argparse --move-unknown n/new -- $argv + for arg in $argv if path is --type dir $from/$arg set --function from $from/$arg@@ -13,6 +15,10 @@ end end set --function types file,dir + if set --query _flag_new + set --function types dir + end + for entry in $(path filter --type $types --perm exec $from/*) printf "%s\t%s\n" $(path basename $entry) $(__scriptura_help $entry) end
M functions/__scriptura_seen_script.fish → functions/__scriptura_seen_script.fish
@@ -4,6 +4,8 @@ or set --function argv (commandline -xpc)[2..] set --function target $SCRIPTURA_ROOT + argparse --stop-nonopt --move-unknown n/new -- $argv + if not set --query argv[1] return 1 end@@ -16,6 +18,10 @@ set --function target $target/$arg else if path is --type file --perm exec $target/$arg return 0 else + if set --query _flag_new + # the first non-directory argument is probably a script name + return 0 + end break end end