Skip to content

Instantly share code, notes, and snippets.

@edvardm
Created May 27, 2020 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edvardm/939f7e3078eb9b57b0d1c869a237e3de to your computer and use it in GitHub Desktop.
Save edvardm/939f7e3078eb9b57b0d1c869a237e3de to your computer and use it in GitHub Desktop.
Shell script to quickly create an invoke task (stub)
mktask () {
name=$1
cmd="${@:2}"
preamble="import os\nimport sys\nfrom invoke import task"
if [ -z $cmd ]
then
echo "mktask <name> <cmd with any args>"
return 0
fi
# create tasks file if not present
test -f tasks.py || (echo $preamble >> tasks.py)
# add new task
\cat <<EOF >> tasks.py
@task
def $name(c):
c.run(f"$cmd", echo=True, pty=True)
EOF
# finally, open last line of the file with proper editor
$EDITOR tasks.py +
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment