function scriptura argparse --stop-nonopt h/help n/new e/edit w/which c/cat -- $argv or return if not path is $SCRIPTURA_ROOT if set --query _flag_new mkdir $SCRIPTURA_ROOT else echo \$SCRIPTURA_ROOT $SCRIPTURA_ROOT does not exist, use `$(status function) --new` to create it return 1 end end if not count $argv >/dev/null __scriptura_usage return 0 end set --function target $SCRIPTURA_ROOT set --function stop_search 0 for i in (seq 1 (count $argv)) if test "$argv[$i]" = -- set --function stop_search $i break else if path is --type dir $target/$argv[$i] set --function target $target/$argv[$i] else if path is --type file $target/$argv[$i]; or set --query _flag_new set --function script $target/$argv[$i] set --function target $target/$argv[$i] break else break end end set --local begin (math $i + 1) if test $begin -gt (count $argv) set begin 1 end set --local remaining $argv[$begin..-1] if set --query _flag_help __scriptura_help $target return $status end if set --query _flag_new __scriptura_new $target return $status end if set --query _flag_edit __scriptura_edit $target return $status end if set --query _flag_which __scriptura_which $target $remaining return $status end if set --query _flag_cat __scriptura_cat $target return $status end if set --query script if path is --perm exec $target $target $remaining else echo "scriptura: $target is not executable" >&2 __scriptura_cat $target end else if path is --type dir $target; and test $stop_search -gt 0 __scriptura_list $target else echo "scriptura: don't know what to do with target \"$remaining\"" >&2 end end