dotfiles

Dash Eclipse's dotfiles
git clone git://ezup.dev/dotfiles.git
Log | Files | Refs | README | LICENSE

git-arc (1156B)


      1#!/usr/bin/env sh
      2
      3slugify() {
      4	# https://github.com/Mayeu/slugify/blob/master/slugify#L24
      5	export LANG=POSIX
      6	export LC_ALL=POSIX
      7	sed -e 's/[^[:alnum:]]/-/g' \
      8		| tr -s '-' \
      9		| sed -e 's/-$//'
     10}
     11
     12modify_zipnote() {
     13	filename="$1"
     14	note="$(zipnote $filename)"
     15	author="$(git log -1 --pretty='%an')"
     16	info="$(git --no-pager show --pretty='format:%C(auto)%h (%s, %ai)' --stat)"
     17	echo "${note}\nAuthor: ${author}\n${info}" | zipnote -w "$filename"
     18}
     19
     20usage() {
     21	: "${progname:="${0##*/}"}"
     22	cat <<_EOF | GREP_COLORS='ms=1' egrep --color "$progname|$"
     23Usage: $progname [tar|tar.gz|zip]       create archive
     24_EOF
     25	exit 0
     26}
     27
     28case $1 in
     29	"") FORMAT=tar.gz;;
     30	tar|tar.gz|zip) FORMAT=$1;;
     31	*) usage;;
     32esac
     33
     34reponame="$(basename $(git rev-parse --show-toplevel))"
     35filename="${reponame}_$(git --no-pager log -1 --oneline --pretty='%as %s' | slugify).${FORMAT}"
     36
     37if [ -f "$filename" ]; then
     38	echo "Found exsiting archive: $(tput bold)${filename}$(tput sgr0)"
     39	exit 1
     40else
     41	git archive --format="$FORMAT" -o "$filename" --prefix="${reponame}/" HEAD
     42	echo "$filename"
     43	if [ "$FORMAT" = "zip" ]; then
     44		modify_zipnote "$filename"
     45		unzip -l "$filename"
     46	fi
     47fi
     48exit 0