Commit d36c6f93d8dde634a1232495944a6f6adbce2ea4

Authored by Shrikant Sharat
1 parent d985103372

Implemented `antigen-snapshot` command.

Creates a snapshot file with some basic metadata information and pairs of repo
urls and their version hashes. Tests included.

Showing 2 changed files with 59 additions and 0 deletions Side-by-side Diff

... ... @@ -349,6 +349,43 @@ antigen-list () {
349 349 fi
350 350 }
351 351  
  352 +antigen-snapshot () {
  353 +
  354 + local snapshot_file="${1:-antigen-shapshot}"
  355 +
  356 + # The snapshot content lines are pairs of repo-url and git version hash, in
  357 + # the form:
  358 + # <version-hash> <repo-url>
  359 + local snapshot_content="$(-antigen-echo-record | sed 's/ .*$//' | sort -u |
  360 + while read url; do
  361 + dir="$(-antigen-get-clone-dir "$url")"
  362 + version_hash="$(cd "$dir" && git rev-parse HEAD)"
  363 + echo "$version_hash $dir"
  364 + done)"
  365 +
  366 + {
  367 + # The first line in the snapshot file is for metadata, in the form:
  368 + # key='value'; key='value'; key='value';
  369 + # Where `key`s are valid shell variable names.
  370 +
  371 + # Snapshot version. Has no relation to antigen version. If the snapshot
  372 + # file format changes, this number can be incremented.
  373 + echo -n "version='1';"
  374 +
  375 + # Snapshot creation date+time.
  376 + echo -n " created_on='$(date)';"
  377 +
  378 + # Add a checksum with the md5 checksum of all the snapshot lines.
  379 + local checksum="$(echo "$snapshot_content" | md5sum)"
  380 + echo -n " checksum='${checksum%% *}';"
  381 +
  382 + # A newline after the metadata and then the snapshot lines.
  383 + echo "\n$snapshot_content"
  384 +
  385 + } > "$snapshot_file"
  386 +
  387 +}
  388 +
352 389 antigen-help () {
353 390 cat <<EOF
354 391 Antigen is a plugin management system for zsh. It makes it easy to grab awesome
... ... @@ -0,0 +1,22 @@
  1 +Load a couple of plugins.
  2 +
  3 + $ antigen-bundle $PLUGIN_DIR
  4 + Cloning into '*'... (glob)
  5 + done.
  6 + $ antigen-bundle $PLUGIN_DIR2
  7 + Cloning into '*'... (glob)
  8 + done.
  9 +
  10 +Create a snapshot file.
  11 +
  12 + $ test -f snapshot-file
  13 + [1]
  14 + $ antigen-snapshot snapshot-file
  15 + $ test -f snapshot-file
  16 +
  17 +See the contents of the snapshot file.
  18 +
  19 + $ cat snapshot-file
  20 + version='1'; created_on='*'; checksum='*'; (glob)
  21 + .{40} .*-test-plugin (re)
  22 + .{40} .*-test-plugin2 (re)