split helpers into files
1 file changed, 3 insertions(+), 111 deletions(-)
changed files
M functions/scriptura.fish → functions/scriptura.fish
@@ -2,13 +2,6 @@ function scriptura argparse --stop-nonopt h/help n/new e/edit w/which c/cat -- $argv or return - set --query SCRIPTURA_ROOT - or if set --query SD_ROOT - set --function SCRIPTURA_ROOT $SD_ROOT - else - set --function SCRIPTURA_ROOT "$HOME/sd" - end - if not path is $SCRIPTURA_ROOT if set --query _flag_new mkdir $SCRIPTURA_ROOT@@ -24,9 +17,11 @@ 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]@@ -77,112 +72,9 @@ else echo "scriptura: $target is not executable" >&2 __scriptura_cat $target end - else if path is --type dir $target; and not test "$target" = "$SCRIPTURA_ROOT" + 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 - -function __scriptura_usage - echo "Usage: scriptura [script_name]" - echo "SCRIPTURA_ROOT: $SCRIPTURA_ROOT" - echo "" - __scriptura_list $SCRIPTURA_ROOT -end - -function __scriptura_list --argument-names from - for dir in $(path filter --type dir $from/*) - printf "%-12s -- %-64s\n" "$(path basename $dir) ..." $(__scriptura_help $dir) - end - for file in $(path filter --type file --perm exec $from/*) - printf "%-12s -- %-64s\n" $(path basename $file) $(__scriptura_help $file) - end -end - -function __scriptura_help --argument-names file_or_dir - if path is --type dir $file_or_dir - set --function help_file $file_or_dir/help - else - set --function help_file $file_or_dir.help - end - - if path is --type file $help_file - __scriptura_cat $help_file - else if path is --type dir $file_or_dir - echo "$(path basename $file_or_dir) commands" - else if path is --type file $file_or_dir - echo $(__scriptura_desc $file_or_dir) - else - echo "Unknown type" - end -end - -function __scriptura_desc --argument-names file - string match --groups-only --regex '^#\s*([^!].*)$' <$file | string join "\n" -end - -function __scriptura_file_help --argument-names file - string match --all --groups-only --regex '^#\s*([^!].*)$' <$file -end - -function __scriptura_new --argument-names target - if not path is --type dir (path dirname $target) - mkdir -p $target - end - - if path is --type file $target - echo "Error: $target already exists" - return 1 - end - - printf "%s\n\n" "#!/usr/bin/env fish" >$target - chmod +x $target - - __scriptura_edit $target -end - -function __scriptura_edit --argument-names script_path - if not set --query SCRIPTURA_EDITOR - set --function SCRIPTURA_EDITOR $( - if set --query SD_EDITOR - echo $SD_EDITOR - else if set --query VISUAL - echo $VISUAL - else if set --query EDITOR - echo $EDITOR - else if command --query vim - echo vim - else if command --query nano - echo nano - else if command --query vi - echo vi - else - echo "Don't know which editor to use, set \$SCRIPTURA_EDITOR, \$VISUAL or \$EDITOR!" >& 2 - return 1 - end - ) - end - - eval $SCRIPTURA_EDITOR $script_path -end - -function __scriptura_cat --argument-names script_path - if not set --query SCRIPTURA_CAT - if set --query SD_CAT - set --function SCRIPTURA_CAT $SD_CAT - else - set --function SCRIPTURA_CAT cat - end - end - - eval $SCRIPTURA_CAT $script_path -end - -function __scriptura_which --argument-names script_path - if path is --type file --perm exec $script_path - echo $script_path - else - return 1 - end -end