2020-09-29 05:09:04 +00:00
|
|
|
#!/usr/bin/env fish
|
|
|
|
|
2020-10-13 16:25:31 +00:00
|
|
|
set -g run_func_prefix 'run'
|
|
|
|
|
|
|
|
if test -f ./run.fish
|
|
|
|
source ./run.fish
|
|
|
|
else
|
|
|
|
echo 'No run.fish found in current directory. Please copy the template from https://github.com/mitchell/run.fish'
|
|
|
|
exit 1
|
|
|
|
end
|
2020-09-29 05:09:04 +00:00
|
|
|
|
|
|
|
function main
|
2020-10-13 23:53:49 +00:00
|
|
|
alias $run_func_prefix\_default=$run_func_prefix\_help
|
2020-10-06 02:00:05 +00:00
|
|
|
define_aliases
|
|
|
|
|
2020-09-29 05:09:04 +00:00
|
|
|
for command in $argv
|
|
|
|
set -l last_status $status
|
|
|
|
test $last_status -gt 0; and exit $last_status
|
|
|
|
|
2020-10-13 16:25:31 +00:00
|
|
|
execute_command $run_func_prefix $command
|
2020-10-13 03:38:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if test -z "$argv"
|
2020-10-13 16:25:31 +00:00
|
|
|
execute_command $run_func_prefix default
|
2020-09-29 05:09:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function execute_command -a prefix command
|
|
|
|
set -l args (string split --max 1 $run_arg_delimeter $command)
|
2020-10-13 23:53:49 +00:00
|
|
|
set -l func $prefix\_$args[1]
|
2020-09-29 05:09:04 +00:00
|
|
|
|
2020-10-13 03:38:53 +00:00
|
|
|
define_default_functions $prefix
|
|
|
|
|
2020-09-29 05:09:04 +00:00
|
|
|
if functions -q $func
|
|
|
|
$func $args[2]
|
2020-10-13 16:25:31 +00:00
|
|
|
else if test -z "$command"
|
|
|
|
execute_command $prefix default
|
2020-09-29 05:09:04 +00:00
|
|
|
else
|
|
|
|
echo "$prefix command '$command' does not exist"
|
2020-09-29 19:32:30 +00:00
|
|
|
exit 1
|
2020-09-29 05:09:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-13 03:38:53 +00:00
|
|
|
function define_default_functions
|
|
|
|
set -g prefix $argv[1]
|
|
|
|
|
2020-10-13 23:53:49 +00:00
|
|
|
function _$prefix\_commands -d 'List all available commands'
|
|
|
|
set -l names (functions --names | grep $prefix\_)
|
2020-10-13 03:38:53 +00:00
|
|
|
|
|
|
|
for name in $names
|
|
|
|
set -l details (functions -D -v $name)
|
|
|
|
set -l description $details[5]
|
2020-10-13 23:53:49 +00:00
|
|
|
set -l short_name (string replace $prefix\_ '' $name)
|
2020-10-13 03:38:53 +00:00
|
|
|
|
|
|
|
if test (string length $short_name) -ge 8
|
|
|
|
echo $short_name\t$description
|
|
|
|
else
|
|
|
|
echo $short_name\t\t$description
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-13 23:53:49 +00:00
|
|
|
function $prefix\_help -a command -d 'Print help menu or command definition'
|
2020-10-13 03:38:53 +00:00
|
|
|
if test -n "$command"
|
2020-10-13 23:53:49 +00:00
|
|
|
functions $prefix\_$command
|
2020-10-13 03:38:53 +00:00
|
|
|
else
|
|
|
|
echo 'Here are the available commands:'\n
|
2020-10-13 23:53:49 +00:00
|
|
|
_$prefix\_commands
|
|
|
|
echo \n"To see a command's definition do `run help$run_arg_delimeter{command}`"
|
2020-10-13 03:38:53 +00:00
|
|
|
echo "To see a subcommand group's help menu do `run {command}$run_arg_delimeter""help`"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-29 05:09:04 +00:00
|
|
|
main $argv
|