~ecs/tm

0c7220a193cdf52490233ad1497606420ee24f8f — Ember Sawady 3 years ago 9729bf9
lib.sh: alpha-sort
1 files changed, 42 insertions(+), 40 deletions(-)

M lib.sh
M lib.sh => lib.sh +42 -40
@@ 1,50 1,12 @@
unset CDPATH
path="$PWD"
while ! [ -d "$path/.tm" ] || [ "z$path" = "z/" ]; do
	path="$path/.."
done
cd -- "$path"
export TM_DIR="${TM_DIR:-$PWD/.tm}"
cd - >/dev/null
export TM_WS="${TM_WS:-$TM_DIR/..}"
export TM_IGNORE="${TM_IGNORE:-$TM_WS/.tmignore}"
TMPDIR="${TMPDIR:-/tmp}"
# TODO: replace this with something POSIX
TMPDIR="$(mktemp -d "$TMPDIR/tm.XXXXXXX")"
trap "rm -rf '$TMPDIR'; exit" INT
trap "rm -rf '$TMPDIR'" EXIT

write() {
	tmp="$TMPDIR/write"
	cat >"$tmp"
	# TODO: replace this with something POSIX
	hash="$(sha512sum -- "$tmp" | cut -f1 -d' ')"
	cat "$tmp" >"$TM_DIR/objects/$hash"
	rm -f -- "$tmp"
	printf "%s\n" "$hash"
}

ch() {
	printf "%s\n" "$2" | cut -c"$1"
}

postfix() {
	len="$(printf "%s" "$1" | wc -c)"
	while read -r "line"; do
		linelen="$(printf "%s" "$line" | wc -c)"
		post="$(printf "%s" "$line" | cut -c"$((linelen - len + 1))-" 2>/dev/null || true)"
		[ "z$post" = "z$1" ] && printf "%s\n" "$line"
	done
}

abort() {
	printf "%s\n" "$@" >&2
	exit 1
}

objtype() {
	ref="$(tm resolve-ref "$1")"
	tm cat "$ref" | head -n1
ch() {
	printf "%s\n" "$2" | cut -c"$1"
}

isignored() {


@@ 64,3 26,43 @@ isignored() {
	done
	return 1
}

objtype() {
	ref="$(tm resolve-ref "$1")"
	tm cat "$ref" | head -n1
}

postfix() {
	len="$(printf "%s" "$1" | wc -c)"
	while read -r "line"; do
		linelen="$(printf "%s" "$line" | wc -c)"
		post="$(printf "%s" "$line" | cut -c"$((linelen - len + 1))-" 2>/dev/null || true)"
		[ "z$post" = "z$1" ] && printf "%s\n" "$line"
	done
}

write() {
	tmp="$TMPDIR/write"
	cat >"$tmp"
	# TODO: replace this with something POSIX
	hash="$(sha512sum -- "$tmp" | cut -f1 -d' ')"
	cat "$tmp" >"$TM_DIR/objects/$hash"
	rm -f -- "$tmp"
	printf "%s\n" "$hash"
}

path="$PWD"
while ! [ -d "$path/.tm" ] || [ "z$path" = "z/" ]; do
	path="$path/.."
done
cd -- "$path"
export TM_DIR="${TM_DIR:-$PWD/.tm}"
cd - >/dev/null
export TM_WS="${TM_WS:-$TM_DIR/..}"
export TM_IGNORE="${TM_IGNORE:-$TM_WS/.tmignore}"

TMPDIR="${TMPDIR:-/tmp}"
# TODO: replace this with something POSIX
TMPDIR="$(mktemp -d "$TMPDIR/tm.XXXXXXX")"
trap "rm -rf '$TMPDIR'; exit" INT
trap "rm -rf '$TMPDIR'" EXIT