Last active
March 3, 2017 20:12
-
-
Save dluc/7d4950d4d4c046fcd3162fddaba0dca5 to your computer and use it in GitHub Desktop.
Keeping a set of gist-files up to date
This file contains 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
#!/usr/bin/env bash | |
# Source: https://gist.github.com/7d4950d4d4c046fcd3162fddaba0dca5 | |
# | |
# * Works with `gist` CLI (https://github.com/defunkt/gist) | |
# * Files are created manually | |
# * Requires login: `gist --login` | |
# * Gist URL: https://gist.github.com/<gist id> | |
# * Raw URL: https://gist.githubusercontent.com/<user name>/<gist id>/raw/<file name> | |
# List your files here, one file per line: | |
# Format: <gist id><blank space><file name> | |
MY_FILES=$(cat <<-END | |
6fec92c99a14b0f2e2f6f03d78a8b830 myfile-something-foo.conf | |
14c376e5e2f6f03d78a8b8306fec92c9 application.sh | |
e2f6fb0f2121c4f1c391d4c376e5e291 public-data.json | |
76e5e2f6f03d78a8b8306fec92f1c4f1 feed.rss | |
91c3f6f03d78a2f03d88306fec2c9940 hellow-world.css | |
END | |
) | |
# -------------------------------------------------------------- | |
# -------------------------------------------------------------- | |
# -------------------------------------------------------------- | |
update() | |
{ | |
FILE=$1 | |
ID=$2 | |
DOTS='.....................................................' | |
CHECKSUM=".$FILE._gistcs" | |
if [ ! -f "$CHECKSUM" ]; then touch "$CHECKSUM"; fi | |
PREV=$(cat "$CHECKSUM") | |
CURR=$(cat "$FILE" | shasum -b | cut -d' ' -f 1) | |
printf "[%s] %s %s" $ID $FILE "${DOTS:${#FILE}}" | |
if [ "$CURR" != "$PREV" ]; then | |
printf " updating ... " | |
gist -u "$ID" "$FILE" && printf "$CURR" > "$CHECKSUM" | |
else | |
echo " up to date" | |
fi | |
} | |
LIST=() | |
for VALUE in $MY_FILES; do | |
LIST+=($VALUE) | |
done | |
while [ ${#LIST[@]} -gt 0 ]; do | |
ID=${LIST[0]} | |
FILE=${LIST[1]} | |
LIST=("${LIST[@]:2}") | |
update "$FILE" "$ID" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment