All Projects → jez → bask

jez / bask

Licence: other
😎 Bask in the convenience of a task runner for bash

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to bask

Ten Hands
⚡ Simplest way to organize and run command-line tasks
Stars: ✭ 228 (+300%)
Mutual labels:  task-runner
runfile
Command line for your projects
Stars: ✭ 22 (-61.4%)
Mutual labels:  task-runner
django-simple-task
Simple background task for Django 3
Stars: ✭ 88 (+54.39%)
Mutual labels:  task-runner
taskrunner.nvim
🏃 Runs Gulp/Gruntfiles in terminal splits
Stars: ✭ 13 (-77.19%)
Mutual labels:  task-runner
myrmidon
A rofi task / command executor
Stars: ✭ 82 (+43.86%)
Mutual labels:  task-runner
alfons
🚀 Task runner for Lua and MoonScript.
Stars: ✭ 17 (-70.18%)
Mutual labels:  task-runner
Taskr
A fast, concurrency-focused task automation tool.
Stars: ✭ 2,421 (+4147.37%)
Mutual labels:  task-runner
arelo
a simple auto reload (live reload) utility
Stars: ✭ 54 (-5.26%)
Mutual labels:  task-runner
gow
Missing watch mode for Go commands. Watch Go files and execute a command like "go run" or "go test"
Stars: ✭ 343 (+501.75%)
Mutual labels:  task-runner
elk
🦌 Minimalist yaml based task runner
Stars: ✭ 43 (-24.56%)
Mutual labels:  task-runner
node-saku
Ⓜ️ Markdown-based task runner
Stars: ✭ 71 (+24.56%)
Mutual labels:  task-runner
ngx upstream jdomain
An asynchronous domain name resolution module for nginx upstream.
Stars: ✭ 71 (+24.56%)
Mutual labels:  task-runner
gilbert
Build system and task runner for Go projects
Stars: ✭ 105 (+84.21%)
Mutual labels:  task-runner
composer
API-first task runner with three methods: task, run and watch.
Stars: ✭ 35 (-38.6%)
Mutual labels:  task-runner
ansible-taskrunner
Ansible Taskrunner - ansible-playbook wrapper with YAML-abstracted python click cli options!
Stars: ✭ 14 (-75.44%)
Mutual labels:  task-runner
Dramatiq
A fast and reliable background task processing library for Python 3.
Stars: ✭ 2,844 (+4889.47%)
Mutual labels:  task-runner
bask
A runner and framework for command-centric Bash scripts.
Stars: ✭ 31 (-45.61%)
Mutual labels:  task-runner
rote
Automate everything.
Stars: ✭ 66 (+15.79%)
Mutual labels:  task-runner
rush
🏃‍♀️ Minimalistic CLI Tool for Managing and Running Bash Snippets
Stars: ✭ 35 (-38.6%)
Mutual labels:  task-runner
duty
A simple task runner.
Stars: ✭ 36 (-36.84%)
Mutual labels:  task-runner

Bask

Travis npm Gitter standard-readme compliant tl;drLegal LGPL 3.0

😎 Bask in the convenience of a task runner for bash

Bask is a task runner for Bash. It's like Make with a bunch of shell targets, but without the .PHONY's everywhere, and nicer because there's no more Make syntax. The main difference is that tasks are always run in Bask, but only run if targets are out of date in Make.

If you're writing a Makefile with all .PHONY targets, chances are that Bask is really what you want.

Table of Contents

Background

Bask was initially forked from bash-task-runner. It was forked for a couple reasons:

  • I needed to vendor it for an unrelated project.
  • I wanted to drop the dependency on GNU coreutils.
  • I wanted to improve the name 😏

I actively follow upstream changes. If I'm missing a compatible feature that was added upstream, feel free to notify me via an issue, pull request, or message on Gitter.

Bask's first commit is a squashed version of bash-task-runner at the time it was forked. For a complete list of changes, just use the commit log.

Install

Each of the below installation methods is differentiated along two properties:

  • Local to project
    • Whether Bask will be installed locally to your project or globally on a system.
    • This is good for CI builds and spinning up multiple people on your project
  • CLI-enabled
    • Whether you will be able to use the bask command from your prompt.
    • Useful for local development, tab completion, and convenience.

You may want to combine multiple installation methods in order to satisfy both of these requirements. In particular, we recommend Simple (vendored) with a method that gives you a CLI and is compatible with your system.

Local to Project CLI-enabled
Simple (vendored) 🚫
Submodule (vendored)
Homebrew 🚫
NPM
Git + PATH 🚫

Dependencies

Currently Bask requires Bash 4.2+.

Simple (vendored)

Just drop src/bask.sh anywhere in your project folder:

wget https://raw.githubusercontent.com/jez/bask/master/src/bask.sh

Then skip to Usage for how to use a vendored Bask installation.

Submodule (vendored)

If you'd like a slightly better story around updating Bask when vendored, you can use a Git submodule, if you're familiar with submodules:

git submodule add https://github.com/jez/bask

Note that if submodules are too heavy-handed, you can get the same effect (without the ease of updating) by just unzip'ing Bask's source into your project.

You should now be able to access bask.sh within the submodule. Additionally, you can access the CLI with ./bask/bin/bask. You can make this more ergonomic by altering your PATH:

export PATH="$PATH:./bask/bin"

Then skip to Usage to learn more.

Homebrew

On OS X, installing Bask globally is simple if you have Homebrew:

brew install jez/formulae/bask

Then skip to Usage to learn more.

NPM

If you don't mind the additional dependency on the NPM ecosystem, you can install Bask with NPM:

# --- Local to Project --- #
npm install --save bask

# to enable CLI:
export PATH="PATH:./node_modules/.bin"

# --- Global --- #
npm install -g bask

Then skip to Usage to learn more.

Git + PATH

If Bask is not available in a package manager for your system, you can clone Bask to your computer, and adjust your PATH to contain the installation location:

git clone https://github.com/jez/bask

export PATH="$PATH:$(pwd)/bask/bin"

Then skip to Usage for how to use the CLI.

Usage

You use Bask in conjunction with a Baskfile. A basic Baskfile looks like this:

task_foo() {
  ## Do something...
}

task_bar() {
  ## Do something...
}

Optional: if you want your Baskfile to be a standalone script, add this to the beginning (works best in conjunction with a vendored installation):

#!/usr/bin/env bash
cd "$(dirname "$0")" || exit
source ./path/to/bask.sh

You invoke Bask using bask [task ...]:

$ bask foo bar
[21:37:43.754] Starting 'foo'
[21:37:43.755] Finished 'foo' after 1 ms
[21:37:43.756] Starting 'bar'
[21:37:43.757] Finished 'bar' after 1 ms

Or, if your Baskfile sources bash.sh:

bash Baskfile foo bar

CLI

NOTE: Please see bask -h for complete, up-to-date CLI usage information.

Usage: bask [options] [task] [task_options] ...
Options:
  -C <dir>, --directory=<dir>  Change to <dir> before doing anything.
  --completion=<shell>         Output code to activate task completions.
                               Supported shells: 'bash'.
  -f <file>, --file=<file>     Use <file> as a Baskfile.
  -l, --list-tasks             List available tasks.
  -h, --help                   Print this message and exit.

Flags

All flags you pass after the task names are passed to your tasks.

task_foo() {
  echo ${@}
}

$ bask foo --production
--production

To pass options to the bask CLI specifically, you must provide them before any task names:

$ bask -f scripts/tasks.sh foo

Tab Completion

The bask CLI supports autocompletion for task names (bash only). Simply add the following line your ~/.bashrc:

eval $(bask --completion=bash)

API

This section covers all the features of Bask.

Baskfile

Your Baskfile can be named any of the following. Using a .sh suffix helps with things like editor syntax highlighting.

Baskfile
Baskfile.sh
baskfile
baskfile.sh

Default Tasks

You can specify a default task in your Baskfile. It will run when no arguments are provided. There are two ways to do this:

task_default() {
  # do something ...
}
bask_default_task="foo"
task_foo() {
  # do something ...
}

Methods

Bask exposes a number of functions for manipulating dependencies among tasks, for logging, and for a few utilities.

bask_depends

Alias: bask_sequence

This function is for declaring dependencies of a task. It should be invoked within another task.

Usage: bask_depends [task ...]

task_default() {
  bask_depends foo bar
  # Output:
  # [21:50:33.194] Starting 'foo'
  # [21:50:33.195] Finished 'foo' after 1 ms
  # [21:50:33.196] Starting 'bar'
  # [21:50:33.198] Finished 'bar' after 2 ms
}

If any task return non-zero, the entire sequence of tasks is aborted with an error.

Note that return codes can be bubbled up using ... || return, so you can conveniently abort tasks prematurely like this:

maybe_error() {
  return $(($RANDOM % 2))
}

task_try() {
  echo "Bad"
  maybe_error || return    # <-- bubbles error up if error
  # code for when no error
}

task_finally() {
  echo "Good"
}

task_foo() {
  bask_depends try finally
}

bask_fork_join

Alias: bask_parallel

Bask also allows for spawning independent work in parallel, and resuming the task when all tasks have completed:

Usage: bask_fork_join [task ...]

task_default() {
  bask_fork_join sleep3 sleep5
  bask_log "after"
  # [21:50:33.194] Starting 'sleep3'
  # [21:50:33.194] Starting 'sleep5'
  # [21:50:36.396] Finished 'sleep3' after 3.20 s
  # [21:50:38.421] Finished 'sleep5' after 5.23 s
  # [21:50:38.422] after
}

Note that all tasks always run to completion, unlike with bask_depends.

bask_run

This will log a timestamp plus the command with its arguments, then run it.

Usage: bask_run <command --with args>

Note that the command must be a simple command--things like pipes, &&, ||, { ... }, etc. will not work.

bask_log

You can log information inside Bask tasks using one of the five bask_log helpers:

Function Description
bask_log Adds a log line (with time), in the foreground color
bask_log_success Same as above, but in green
bask_log_error Same as above, but in red
bask_log_warning Same as above, but in yellow
bask_log_info Same as above, but in cyan
bask_log_debug Same as above, but in gray

Usage: bask_log message

All logging functions have the same usage.

bask_colorize

While the dedicated logging functions are helpful, sometimes you want finer control over your colors.

Usage: bask_colorize <colorname> message

Where colorname is one of

black gray light_gray white
red green yellow blue purple cyan
light_red light_green light_yellow light_blue light_purple light_cyan
# Simple example
bask_colorize purple This will all be purple

# Use with `bask_log` to get a timestamp:
bask_log "$(bask_colorize purple This will all be purple)"

Note that your message will be wrapped with the appropriate color and reset codes. You don't need to worry about manually turning the color back to normal.

bask_list_tasks

The default behavior if no tasks are specified at the command line and no default tasks are registered is to list all available tasks. You can manually invoke that with this function.

Usage: bask_list_tasks

task_list() {
  bask_list_tasks
}

bask_is_task_defined

Utility function for checking whether a list of tasks are defined. Used internally, but exposed externally.

Usage: bask_is_task_defined [task ...]

Note that you can pass in more than one task for checking.

Alternatively, you can use bask_is_task_defined_verbose, which will do the same checks, but log an error if any task is not defined.

Contribute

Bask was forked from bash-task-runner. Chances are that if you have an issue or pull request it can be made against that upstream repo.

If your issue pertains to functionality specifically only provided here, then feel free to voice your concerns here. If you're confused where to make the request, feel free to ask in Gitter first.

License

GNU Lesser General Public License v3 (LGPL-3.0). See License.md

Copyright (c) Commits
Aleksej Komarov 8a28f72
Jake Zimmerman 5e92344+
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].