sgit-cat 414 B

123456789101112131415
  1. #! /bin/bash
  2. [[ $# -ne 1 ]] && echo "Usage: sgit-cat SHA1SUM
  3. Outputs contents of git object associated with SHA1SUM."
  4. objdir="$PWD/.git/objects"
  5. sha=$1
  6. sha_dir="$objdir"/$(echo $sha | awk '{print substr($1,1,2)}')
  7. sha_file=$(echo $sha | awk '{print substr($1,3)}')
  8. [[ ! -f "$sha_dir"/"$sha_file" ]] && echo "No object associated with $sha." && exit 1
  9. openssl zlib -d < "$sha_dir"/"$sha_file" | tr '\000' '\n'