~ecs/tm

86baa2cee81decec4b65cfaa6790688db6ed51d6 — Ember Sawady 3 years ago 4db9571
object-type: initial commit
3 files changed, 8 insertions(+), 6 deletions(-)

M lib.sh
A tm-object-type
M tm-resolve-path
M lib.sh => lib.sh +0 -5
@@ 27,11 27,6 @@ isignored() {
	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

A tm-object-type => tm-object-type +7 -0
@@ 0,0 1,7 @@
#!/bin/sh

. "$(dirname -- "$0")/lib.sh"
[ $# -eq 1 ] || abort "usage: tm object-type <ref>"

ref="$(tm resolve-ref "$1")" || exit 1
tm cat "$ref" | head -n1

M tm-resolve-path => tm-resolve-path +1 -1
@@ 36,7 36,7 @@ shift "$((OPTIND - 1))"
ref="$(tm resolve-ref "$1")" || abort "error: invalid ref $1"
[ "z$2" = "z/" ] || [ "z$2" = "z." ] && printf "%s\n" "$ref" && exit
dirref="$(tm resolve-path -- "$1" "$(dirname -- "$2")")"
[ "z$(objtype "$dirref")" != "ztree" ] && abort "error: not a directory: $2"
[ "z$(tm object-type "$dirref")" != "ztree" ] && abort "error: not a directory: $2"
line="$(tm cat "$dirref" | postfix " $(basename -- "$2")" | cut -f"$field" -d' ' | head -n1)"
[ -z "$line" ] && abort "error: file $2 not found"
printf "%s\n" "$line"