Last active
March 28, 2020 17:08
-
-
Save kriskowal/8bff7993712c328d945710800da8c42c to your computer and use it in GitHub Desktop.
shell memo
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
#!/bin/bash | |
# Very slow build step. | |
sleep 5 | |
jq .+1 |
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
#!/bin/bash | |
time bash -c 'echo 1 | MEMO=inc-memo memo.sh inc.sh' # Slow | |
time bash -c 'echo 1 | MEMO=inc-memo memo.sh inc.sh' # Fast |
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
#!/bin/bash | |
# Memoizes a pure command, using git notes. | |
# $MEMO is the name of the git note. | |
INPUT=$(git hash-object -w --stdin) | |
OUTPUT=$(git notes --ref="$MEMO" show "$INPUT" 2>/dev/null) || | |
OUTPUT=$(git cat-file blob "$INPUT" | "$@" | git hash-object -w --stdin) && | |
git notes --ref="$MEMO" add -f -m "$OUTPUT" "$INPUT" 2>/dev/null | |
git cat-file blob "$OUTPUT" |
The ideas just keep coming:
# TODO support for argv_0 versioning: if the first command arg is a tracked
# file under the current git repo, then use its sha in place of command
# name to compute $memo_id
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gist-pro-gist https://gist.github.com/jcorbin/2b6be1f57f26e6068516e6bcb663f411 thoughts:
||
and&&
chaining a body can tolerate ;-)MEMO
variable can just be computed by hashing the the command string