all repos — scriptura @ 2ad533210f375712ba2e16104c2bf49b9096e9e0

a corner in $HOME for your scripts

fix directory arg handling

Alan Pearce
commit

2ad533210f375712ba2e16104c2bf49b9096e9e0

parent

1ec690340ff66e93e6a54be54fc2f0f3bc3c239b

2 files changed, 48 insertions(+), 36 deletions(-)

changed files
M functions/scriptura.fishfunctions/scriptura.fish
@@ -25,64 +25,67 @@ return 0
end set --function target $SCRIPTURA_ROOT - set --function stop_search 0 + set --function valid 0 for i in (seq 1 (count $argv)) if test "$argv[$i]" = -- - set --function stop_search $i + set --function valid $i break else if path is --type dir $target/$argv[$i] set --function target $target/$argv[$i] + set --function valid $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] + set --function valid $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] + set --local remaining $argv[(math $valid + 1)..-1] - if set --query _flag_help - __scriptura_help $target - return $status - end + if test $valid -gt 0 - if set --query _flag_new - __scriptura_new $target - return $status - end + if set --query _flag_help + __scriptura_help $target + return $status + end - if set --query _flag_edit - __scriptura_edit $target - return $status - end + if set --query _flag_new + __scriptura_new $target + return $status + end - if set --query _flag_which - __scriptura_which $target $remaining - return $status - end + if set --query _flag_edit + __scriptura_edit $target + return $status + end - if set --query _flag_cat - __scriptura_cat $target - return $status - end + if set --query _flag_which + __scriptura_which $target $remaining + return $status + end - if set --query script - if path is --perm exec $target - $target $remaining - else - echo "scriptura: $target is not executable" >&2 + if set --query _flag_cat __scriptura_cat $target + return $status 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 + + if set --query script + if path is --perm exec $target + $target $remaining + return $status + else + echo "scriptura: $target is not executable" >&2 + __scriptura_cat $target + return $status + end + else if path is --type dir $target; and test (count $remaining) -eq 0 + __scriptura_list $target + return $status + end end + echo "scriptura: don't know what to do with target \"$argv\"" >&2 end
M tests/scriptura.fishtests/scriptura.fish
@@ -151,6 +151,15 @@ chmod +x "$test_root/list_test"
scriptura 2>&1 | string match --regex "list_test" ) +# Test: directory listing with argument shows children +@test "directory listing with argument shows children" -n ( + set --global --export SCRIPTURA_ROOT $test_root + mkdir -p "$test_root/test_dir" + printf "#!/usr/bin/env fish\n# Test script\n" > "$test_root/test_dir/test_script" + chmod +x "$test_root/test_dir/test_script" + scriptura test_dir 2>&1 | string match "test_script*" +) + # Test: help file is used for directories @test "help file is used for directories" ( set --global --export SCRIPTURA_ROOT $test_root