all repos — scriptura @ 70e83b0f00a81744295e4335c4db3ef4ad6e9d01

a corner in $HOME for your scripts

initial commit

Alan Pearce
commit

70e83b0f00a81744295e4335c4db3ef4ad6e9d01

1 file changed, 75 insertions(+), 0 deletions(-)

changed files
A completions/scriptura.fish
@@ -0,0 +1,75 @@
+set --query SD_ROOT or set --local SD_ROOT "~/sd" + +complete --command scriptura --no-files + +complete --command scriptura \ + --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SD_ROOT)' \ + --short-option h --long-option help \ + --description 'Display help information' + +complete --command scriptura \ + --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SD_ROOT)' \ + --short-option n --long-option new \ + --description 'Create new script' + +complete --command scriptura \ + --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SD_ROOT)' \ + --short-option e --long-option edit \ + --description 'Edit existing script' + +complete --command scriptura \ + --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SD_ROOT)' \ + --short-option c --long-option cat \ + --description 'Display script content' + +complete --command scriptura \ + --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SD_ROOT)' \ + --short-option w --long-option which \ + --description 'Display script path' + +complete --command scriptura \ + --condition 'not __fish_seen_subcommand_from $(__scriptura_print $SD_ROOT)' \ + --arguments '$(__scriptura_complete $SD_ROOT)' + +complete --command scriptura \ + --condition '__fish_seen_subcommand_from $(__scriptura_print $SD_ROOT)' \ + --condition 'not __scriptura_seen_script $(commandline -xpc)' \ + --condition 'not __fish_seen_argument --short n --long new' \ + --arguments '$(__scriptura_complete $SD_ROOT/$(commandline -xpc)[-1])' + +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 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 $SD_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