all repos — scriptura @ 3bc3dd964a6f4d190040fccefbd9b0e85d1af0d5

a corner in $HOME for your scripts

read remaining args to `--new --` as script content

Alan Pearce
commit

3bc3dd964a6f4d190040fccefbd9b0e85d1af0d5

parent

2ad533210f375712ba2e16104c2bf49b9096e9e0

3 files changed, 18 insertions(+), 5 deletions(-)

changed files
M functions/__scriptura_new.fishfunctions/__scriptura_new.fish
@@ -1,4 +1,6 @@
function __scriptura_new --argument-names target + set --function remaining $argv[2..-1] + if not path is --type dir (path dirname $target) mkdir -p $target end
@@ -8,9 +10,10 @@ echo "Error: $target already exists"
return 1 end - printf "%s\n\n" "#!/usr/bin/env fish" >$target + printf "%s\n%s\n" "#!/usr/bin/env fish" "$remaining" >$target chmod +x $target - __scriptura_edit $target + if test (count $remaining) -eq 0 + __scriptura_edit $target + end end -
M functions/scriptura.fishfunctions/scriptura.fish
@@ -38,7 +38,9 @@ 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 + if not set --query _flag_new + break + end else break end
@@ -54,7 +56,7 @@ return $status
end if set --query _flag_new - __scriptura_new $target + __scriptura_new $target $remaining return $status end
M tests/scriptura.fishtests/scriptura.fish
@@ -91,6 +91,14 @@ touch "$test_root/existing_script"
scriptura --new existing_script 2>&1 | string match --regex "already exists" ) +# Test: --new with -- creates script with remaining arguments +@test "--new with -- creates script with remaining arguments" ( + set --global --export SCRIPTURA_ROOT $test_root + scriptura --new new_script -- echo foo + path is --type file --perm exec "$test_root/new_script" + tail -n 1 "$test_root/new_script" +) = "echo foo" + # Test: --which shows path for executable script @test "--which shows path for executable script" ( set --global --export SCRIPTURA_ROOT $test_root