diff --git a/importable_sw.fish b/functions/sw.fish similarity index 82% rename from importable_sw.fish rename to functions/sw.fish index 7dbb0eb..96437c2 100644 --- a/importable_sw.fish +++ b/functions/sw.fish @@ -1,3 +1,22 @@ +function sw -d 'The fish-based project script runner' + argparse --ignore-unknown 'i-init' -- $argv + set -g cmd_func_prefix 'swim' + + if test -n "$_flag_init" + curl -fsS https://raw.githubusercontent.com/mitchell/swim.fish/master/swim.fish.example >swim.fish + return + end + + if test -f ./swim.fish + source ./swim.fish + else + echo 'No swim.fish found. Run `sw --init` make one.' + return 1 + end + + run_swim_command $cmd_func_prefix $argv +end + function run_swim_command -a prefix argparse --ignore-unknown 'h/help' -- $argv set -l command $argv[2] diff --git a/sw b/sw index 93d7669..ce9aab8 100755 --- a/sw +++ b/sw @@ -1,14 +1,20 @@ #!/usr/bin/env fish -set -g cmd_func_prefix 'swim' - -if test -f ./swim.fish - source ./swim.fish -else - echo 'No swim.fish found in current directory. Please copy the template from https://github.com/mitchell/swim.fish' - exit 1 -end - function main + argparse --ignore-unknown 'i-init' -- $argv + set -g cmd_func_prefix 'swim' + + if test -n "$_flag_init" + curl -fsS https://raw.githubusercontent.com/mitchell/swim.fish/master/swim.fish.example >swim.fish + return + end + + if test -f ./swim.fish + source ./swim.fish + else + echo 'No swim.fish found. Run `sw --init` make one.' + return 1 + end + run_swim_command $cmd_func_prefix $argv end diff --git a/swim.fish b/swim.fish.example similarity index 98% rename from swim.fish rename to swim.fish.example index 67acb5c..c2f43b3 100644 --- a/swim.fish +++ b/swim.fish.example @@ -73,5 +73,5 @@ function swim_fails -d 'This command fails every time' false end -#curl -fsS https://raw.githubusercontent.com/mitchell/swim.fish/master/importable_sw.fish | source +#curl -fsS https://raw.githubusercontent.com/mitchell/swim.fish/master/functions/sw.fish | source #run_swim_command $cmd_func_prefix $argv