Created
May 27, 2020 14:38
-
-
Save edvardm/939f7e3078eb9b57b0d1c869a237e3de to your computer and use it in GitHub Desktop.
Shell script to quickly create an invoke task (stub)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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