#!/bin/ash
# Rustic 'type'.  Tries to tell if a command is a file, function or builtin.
# Mostly from an 8/23/96 muc.lists.netbsd.current-users post
# "improving ash" by Greg A. Woods  (3/3/00  purloined by A. Costa)
# Note: works in a subshell, so it won't find non-exported functions...
# (Fix: make a function that calls this batch with a leading '.')

FauxType()
{
hashv=`hash | eval sed -n \'/function $1\$/p\'`

if [ -n "$hashv" ]	# 1st check for functions
then
    echo "$hashv" | sed 's/^\([^ ]*\) \(.*\)$/\2 is a \1/'
    unset hashv
    return 0
fi

case "$1" in	# the following arbitrary list of builtins will vary
		# between different ash versions...
    .|bg|bltin|cd|echo|eval|exec|exit|export|fg|getopts|hash|jobid|jobs|lc|local|pwd|read|readonly|return|set|setvar|shift|test|trap|umask|unset|wait)
	typeout="$1 is a builtin" ;;
    *)	typeout="$1 not found"
	pathname=`which $1`
	[ -x ${pathname:-/dev/null/} ] && typeout="$1 is $pathname" && break ;;
esac
echo $typeout
unset typeout pathname hashv
}

case Z"$1" in
Z-d) set -x;shift;;	# debug mode...
Z-h|Z) echo "Usage: type command" ; return 2 ;;
Z*) FauxType $1 ;;
esac
