YAKE
Simple script to make Your coding more efficient
by executing long commands using short aliases from local Yakefile


current version: v2.1

Installation


curl -sSf https://yake.amsdard.io/install.sh | sudo -E bash

Requirements

  • perl > 5.0
  • perl-core > 5.0 (only for RHEL Linux)
  • cpan > 1.0 (build-essential package)

Changelog

  • Oct 23, 2017 (v2.1): remove redundant spaces and quotes on --debug level, DOCS internal vars explanation
  • June 1, 2017 (v2.0): bug fixes, initial arguments (--debug, --version, --upgrade and --help), new special task name _tasks, ZSH completion, able to use spaces in argument value
  • December 12, 2016 (v1.1): settings fixes
  • December 1, 2016 (v1.0): FORCE_ALL param, docs fixes

Usage


yake --help
  • yake loads local YAML Yakefile to get tasks and configs

yake   VARIABLE=value [..]   TASK_NAME   COMMAND WITH -PARAMS --AND=values  
  • global settings and Your local _config section variables can be overwritten from console level
  • You can use bash auto-completion or ZSH completion to see and type defined tasks
  • all commands, params and attributes (a string after TASK_NAME)
    will be assigned to $CMD variable
  • all variables with values (as string) will be assigned to $ARGS variable

Features


  • simple YAML structure
  • able to definee commands as string or array
  • recursive commands, thanks to $BIN variable
  • internal recursive and able to overwrite variables
  • bash auto-completion and ZSH completion
  • direct redirection command to bash console
    Environment variables support, interactive
  • special task names _config to display user defined variables and _tasks to display Yakefile tasks

Internal variables


  • $BIN - use instead of static yake command (while running recursive commands). $BIN var will use yake command with all custom defined variables. See --debug example.

    Default: /usr/local/bin/yake BIN="/usr/local/bin/yake"

  • $ARGS - contains all user defined variables. See YELLOW on Usage.

    Default:   (empty)

  • $CMD - contains full command (string located on the task`s right side). See GREEN on Usage.

    Default:   (empty)

  • $FORCE_ALL (0 | 1) - force all sub-tasks to be executed no matter on output code. By default if task`s return code is not 0 (error), whole task is stopped

    Default: 0 (false)

  • $YAKEFILE - Yakefile file name

    Default: Yakefile

Examples


Example content of Yakefile file:
hello_world: echo "hello world"

run: echo "running..." && $CMD

demo:
    - echo "dumping demo vars"
    - echo "VAR1 = $VAR1"
    - echo "VAR3 = $VAR3"
    - $BIN run $CMD

_config:
    VAR1: value1
    VAR2: var2 using $VAR1
    VAR3: var using VAR1="$VAR1" and VAR2=$VAR2

yake hello_world
hello world

yake run uname -i
running...
x86_64

yake --debug VAR=new1 run uname -i
ARGS               VAR=new1
BIN                /usr/local/bin/yake VAR=new1 BIN="/usr/local/bin/yake"
CMD                uname -i
FORCE_ALL          0
VAR                new1
VAR1               one
VAR11              eleven
VAR2               two one
VAR3               tree VAR1="one" and VAR2=two new11
YAKEFILE           Yakefile

echo "running..." && uname -i 

yake VAR1=new1 demo uname -i
dumping demo vars
VAR1 = new1
VAR3 = var using VAR1=value1 and VAR2=var2 using value1
running...
x86_64

yake VAR1="'new value'" VAR3=$(uname -m) _config
VAR3               x86_64
VAR1               new value
VAR11              eleven
VAR2               two new value
VAR3               tree VAR1="new value" and VAR2=two new value
YAKEFILE           Yakefile

TIPS

  • You could use Environment variables, like $HOME but recommended way is to type ${HOME} to split internal settings and ENVs

  • There are 2 ways to pass string with spaces as variable value:
    yake V="'1 2 3'" task or yake V='"1 2 3"' task. You just have to use double quoting (' in " or reverse). You can use Yakefile _config section as well also.

  • Run yake YAKEFILE=/path/yakeefile.yml demo
    to overwrite Yakefile file name

  • By default, if one of commands in specified task fails (return code is more than 0), it stops whole task. To force executing all commands, no matter what code is returned, set FORCE_ALL=1 param.

  • You can execute task recursively using $BIN what enable You to keep all defined command configs.