Replace default commands with more usefull commands and exmaples
This commit is contained in:
parent
479f57997a
commit
2c1a20f125
13
run
13
run
|
@ -1,6 +1,13 @@
|
||||||
#!/usr/bin/env fish
|
#!/usr/bin/env fish
|
||||||
|
|
||||||
|
set -g run_func_prefix 'run'
|
||||||
|
|
||||||
|
if test -f ./run.fish
|
||||||
source ./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
|
||||||
|
|
||||||
function main
|
function main
|
||||||
define_aliases
|
define_aliases
|
||||||
|
@ -9,11 +16,11 @@ function main
|
||||||
set -l last_status $status
|
set -l last_status $status
|
||||||
test $last_status -gt 0; and exit $last_status
|
test $last_status -gt 0; and exit $last_status
|
||||||
|
|
||||||
execute_command 'run' $command
|
execute_command $run_func_prefix $command
|
||||||
end
|
end
|
||||||
|
|
||||||
if test -z "$argv"
|
if test -z "$argv"
|
||||||
execute_command 'run' default
|
execute_command $run_func_prefix default
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -25,6 +32,8 @@ function execute_command -a prefix command
|
||||||
|
|
||||||
if functions -q $func
|
if functions -q $func
|
||||||
$func $args[2]
|
$func $args[2]
|
||||||
|
else if test -z "$command"
|
||||||
|
execute_command $prefix default
|
||||||
else
|
else
|
||||||
echo "$prefix command '$command' does not exist"
|
echo "$prefix command '$command' does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
65
run.fish
65
run.fish
|
@ -1,16 +1,14 @@
|
||||||
# This run.fish script serves as a central place to store frequently run commands for this project.
|
# This run.fish script serves as a central place to store frequently run commands for this project.
|
||||||
|
# Replace command section with your own command functions.
|
||||||
# Source: https://github.com/mitchell/run.fish
|
# Source: https://github.com/mitchell/run.fish
|
||||||
|
|
||||||
### Config ###
|
### Config ###
|
||||||
# Top-level configurations, like function prefixes and argument delimeters
|
# Top-level configurations, like the argument delimeter and aliases.
|
||||||
#
|
#
|
||||||
set -g run_arg_delimeter ':'
|
set -g run_arg_delimeter ':'
|
||||||
|
|
||||||
function define_aliases
|
function define_aliases
|
||||||
alias run_h='run_hello'
|
alias run_default='run_install'
|
||||||
alias run_l='run_lang'
|
|
||||||
|
|
||||||
alias lang_f='lang_fr'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,30 +16,41 @@ end
|
||||||
# Add, edit, and remove commands freely below.
|
# Add, edit, and remove commands freely below.
|
||||||
# To add a command simply create a function with this naming scheme: {run_func_prefix}_{name}.
|
# To add a command simply create a function with this naming scheme: {run_func_prefix}_{name}.
|
||||||
#
|
#
|
||||||
function run_default -d 'Say bonjour to run.fish user'
|
function run_install -a bin_path -d 'Install the run script to a bin folder'
|
||||||
run_lang fr:'run.fish user'
|
if test -z "$bin_path"
|
||||||
end
|
if test -d ~/.local/bin
|
||||||
|
set bin_path ~/.local/bin
|
||||||
function run_hello -d 'Say hello to the world'
|
else if test -d /usr/local/bin
|
||||||
echo 'hello, world!'
|
set bin_path /usr/local/bin
|
||||||
end
|
|
||||||
|
|
||||||
function run_hey -a name -d 'Say hey to someone specific'
|
|
||||||
echo "hey, $name!"
|
|
||||||
end
|
|
||||||
|
|
||||||
function run_lang -a command -d 'Groups lang subcommands'
|
|
||||||
function lang_en -d 'Say hello in english'
|
|
||||||
run_hello
|
|
||||||
end
|
|
||||||
|
|
||||||
function lang_fr -a name -d 'Say hello the world or someone specific, in french'
|
|
||||||
if test -n "$name"
|
|
||||||
echo "bonjour, $name!"
|
|
||||||
else
|
|
||||||
echo 'bonjour, le monde!'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
execute_command 'lang' $command
|
echo "Installing run script to $bin_path."
|
||||||
|
cp ./run $bin_path/
|
||||||
|
end
|
||||||
|
|
||||||
|
function run_lint -d 'Lint fish scripts'
|
||||||
|
fish --no-execute ./run ./run.fish
|
||||||
|
end
|
||||||
|
|
||||||
|
function run_format -d 'Format fish scripts'
|
||||||
|
fish_indent --write ./run ./run.fish
|
||||||
|
end
|
||||||
|
|
||||||
|
function run_hello -a command -d 'This is an example of a subgroup of commands'
|
||||||
|
function hello_world -d 'The classic'
|
||||||
|
echo 'Hello, world!'
|
||||||
|
end
|
||||||
|
|
||||||
|
function hello_name -a name -d 'Say hello to someone specific'
|
||||||
|
echo "Hello, $name!"
|
||||||
|
end
|
||||||
|
|
||||||
|
function hello_fr -d 'Say bonjour'
|
||||||
|
echo 'Bonjour, le monde!'
|
||||||
|
end
|
||||||
|
|
||||||
|
alias hello_default='hello_world'
|
||||||
|
|
||||||
|
execute_command 'hello' $command # this command comes from the run script
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue