2020-09-29 05:09:04 +00:00
|
|
|
#!/usr/bin/env fish
|
2020-09-29 05:45:47 +00:00
|
|
|
# This run(.fish) script serves as a central place to store frequently run commands for this project.
|
|
|
|
# Source: https://github.com/mitchell/run.fish
|
2020-09-29 05:09:04 +00:00
|
|
|
|
|
|
|
### Config ###
|
|
|
|
# Top-level configurations, like function prefixes and argument delimeters
|
2020-09-29 19:32:30 +00:00
|
|
|
#
|
2020-09-29 05:09:04 +00:00
|
|
|
set -g run_func_prefix 'run'
|
|
|
|
set -g run_arg_delimeter ':'
|
|
|
|
|
|
|
|
|
|
|
|
### Commands ###
|
|
|
|
# Add, edit, and remove commands freely below.
|
2020-09-29 05:45:47 +00:00
|
|
|
# To add a command simply create a function with this naming scheme: {run_func_prefix}_{name}.
|
2020-09-29 05:09:04 +00:00
|
|
|
#
|
2020-09-29 19:32:30 +00:00
|
|
|
function run_hello -d 'Say hello to the world'
|
2020-09-29 05:09:04 +00:00
|
|
|
echo 'hello, world!'
|
|
|
|
end
|
|
|
|
|
2020-09-29 19:32:30 +00:00
|
|
|
function run_hey -a name -d 'Say hey to someone specific'
|
2020-09-29 05:09:04 +00:00
|
|
|
echo "hey, $name!"
|
|
|
|
end
|
|
|
|
|
2020-09-29 19:32:30 +00:00
|
|
|
function run_lang -a command -d 'Groups lang subcommands'
|
|
|
|
function lang_en -d 'Say hello in english'
|
2020-09-29 05:09:04 +00:00
|
|
|
run_hello
|
|
|
|
end
|
|
|
|
|
2020-09-29 19:32:30 +00:00
|
|
|
function lang_fr -a name -d 'Say hello the world or someone specific, in french'
|
2020-09-29 05:58:59 +00:00
|
|
|
if test -n "$name"
|
2020-09-29 19:32:30 +00:00
|
|
|
echo "bonjour, $name!"
|
2020-09-29 05:58:59 +00:00
|
|
|
else
|
|
|
|
echo 'bonjour, le monde!'
|
|
|
|
end
|
2020-09-29 05:09:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
execute_command 'lang' $command
|
|
|
|
end
|
|
|
|
|
2020-09-29 19:32:30 +00:00
|
|
|
### Default Commands ###
|
|
|
|
# Below is a set of default commands, like help and commands. Give them a try by doing:
|
|
|
|
# ./run help
|
|
|
|
# ./run help:hello
|
|
|
|
# ./run commands
|
|
|
|
#
|
|
|
|
function "$run_func_prefix"_commands -d 'List all available commands'
|
|
|
|
functions --names | grep $run_func_prefix'_' | string replace $run_func_prefix'_' ''
|
|
|
|
end
|
|
|
|
|
|
|
|
function "$run_func_prefix"_help -a command -d 'Print command definition'
|
|
|
|
if test -n "$command"
|
|
|
|
functions $run_func_prefix'_'$command
|
|
|
|
else
|
|
|
|
echo 'Here are the available commands:'
|
|
|
|
$run_func_prefix'_commands'
|
|
|
|
echo \n"To see a command's definition and description do `./run help$run_arg_delimeter{command}`"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-29 05:09:04 +00:00
|
|
|
### Command Execution ###
|
2020-09-29 05:58:59 +00:00
|
|
|
# Do not edit, unless you want to alter how the script executes commands.
|
2020-09-29 05:09:04 +00:00
|
|
|
#
|
2020-09-29 05:58:59 +00:00
|
|
|
# This script can execute 1 or more commands like make. It can also receive 1 argument per
|
|
|
|
# command or subcommand in the following format: {name}{run_arg_delimeter}{argument}.
|
2020-09-29 05:09:04 +00:00
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
# ./run hello
|
|
|
|
# ./run hey:mitchell
|
2020-09-29 05:58:59 +00:00
|
|
|
# ./run lang:fr:mitchell
|
2020-09-29 05:09:04 +00:00
|
|
|
# ./run hello hey:mitchell lang:fr
|
|
|
|
#
|
|
|
|
function main
|
|
|
|
for command in $argv
|
|
|
|
set -l last_status $status
|
|
|
|
test $last_status -gt 0; and exit $last_status
|
|
|
|
|
|
|
|
execute_command $run_func_prefix $command
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function execute_command -a prefix command
|
|
|
|
set -l args (string split --max 1 $run_arg_delimeter $command)
|
|
|
|
set -l func $prefix'_'$args[1]
|
|
|
|
|
|
|
|
if functions -q $func
|
|
|
|
$func $args[2]
|
|
|
|
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
|
|
|
|
|
|
|
|
main $argv
|