all repos — scriptura @ e9bf47b59387168b9370ec60e84c4c3d0aeebc49

a corner in $HOME for your scripts

add cmd subcommand

Alin
commit

e9bf47b59387168b9370ec60e84c4c3d0aeebc49

parent

36c53cf2a712410e490f62ea03cb9a6628a3bebd

M README.mdREADME.md
@@ -11,6 +11,7 @@
- Uses subcommands instead of flags (`scriptura new` vs `sd -new`) - `--` can be used to separate arguments intended for `scriptura` itself from those intended for the executed command - [Choose your own short alias](#shorter-command-name) +- A new `cmd` subcommand for running external commands on scripts (e.g. `scriptura cmd foobar -- rm`) ## Motivation
M completions/scriptura.fishcompletions/scriptura.fish
@@ -1,6 +1,6 @@
set --query SCRIPTURA_ROOT or set --local SCRIPTURA_ROOT "~/sd" -set --local subcommands run help edit cat which +set --local subcommands run help edit cat which cmd complete --command scriptura --erase
@@ -41,6 +41,12 @@ --condition __fish_use_subcommand \
--exclusive \ --description (__scriptura_describe_function __scriptura_which) \ --arguments which + +complete --command scriptura \ + --condition __fish_use_subcommand \ + --exclusive \ + --description (__scriptura_describe_function __scriptura_cmd) \ + --arguments cmd complete --command scriptura \ --condition "__fish_seen_subcommand_from $subcommands new (__scriptura_subcommands)" \
A functions/__scriptura_cmd.fish
@@ -0,0 +1,15 @@
+function __scriptura_cmd --argument-names target --description "Execute shell command from target directory" + pushd $SCRIPTURA_ROOT + + argparse --move-unknown -- $argv[2..] + + if path is --type file $target + eval $argv $argv_opts $target + else + pushd $target + eval $argv $argv_opts + popd + end + + popd +end
M functions/__scriptura_complete_script.fishfunctions/__scriptura_complete_script.fish
@@ -4,7 +4,7 @@
test (count $argv) -ne 0 or set --function argv (commandline -xpc)[2..] - if contains $argv[1] run help edit cat which new + if contains $argv[1] run help edit cat which new cmd set --erase argv[1] end
M functions/scriptura.fishfunctions/scriptura.fish
@@ -1,5 +1,5 @@
function scriptura --description 'Manage and execute scripts' - set --function valid_subcommands run help new edit which cat + set --function valid_subcommands run help new edit which cat cmd if not set --query --function scriptura_root_var if not set --query SCRIPTURA_ROOT; and set --query SD_ROOT
@@ -102,6 +102,9 @@ __scriptura_which $target $remaining
return $status case cat __scriptura_cat $target $remaining + return $status + case cmd + __scriptura_cmd $target $remaining return $status end