Core Functions - mvaltas/grind GitHub Wiki
The Core defines functions for bare bash and command executions.
Run
These functions define commands that should be run, any argument will be called through eval
.
do_run
Bash line that will be called depending on run checks.
do_run "brew install httpie"
unless_on_path "http"
run
Bash line that will be called immediately.
run "launctl stop com.some.service"
Run checks
Run checks will execute and if they return true do_run
will be executed, if not it will be skipped.
unless
Bash line that will return true if the command given fails.
do_run "brew install jq"
unless "[ -f /usr/local/bin/jq ](/mvaltas/grind/wiki/--f-/usr/local/bin/jq-)"
unless_file
Same as unless "[ -f ARG ](/mvaltas/grind/wiki/--f-ARG-)"
where ARG is the argument given to the function.
do_run "brew install jq"
unless_file "/usr/local/bin/jq"
unless_dir
Same as unless "[ -d ARG ](/mvaltas/grind/wiki/--d-ARG-)"
where ARG is the argument given to the function.
do_run "mkdir ${HOME}/Projects"
unless_dir "${HOME}/Projects"
unless_on_path
Same as unless "type ARG &> /dev/null"
where ARG is the argument given to the function.
do_run "echo 'export PATH=${PATH}:${HOME}/Projects/grind' >> ${HOME}/.bash_profile"
unless_on_path "grind"
unless_link
Same as unless "[ -L ARG ](/mvaltas/grind/wiki/--L-ARG-)"
where ARG is the argument given to the function.
do_run "ln -s /this/file /to/symbolic/link"
unless_link "/to/symbolic/link"
unless_running
Same as unless "pgrep ARG &> /dev/null
where ARG is the argument given to the function.
do_run "service start ssh"
unless_running "sshd"
if_
if_
is the opposite of unless
, it will return true if the command given returns passes.
Control
run_def DEF
References another definition to run. The rules for force, dry-run and idempotency still apply. If two different definitions let's say A
and B
refer to a definition C
. C
will execute its commands only once. This should be used carefully as a circular dependency won't be caught by grind
and will loop forever.
stop_on_fail
It will stop the whole execution if the last command ran failed.