#!/bin/bash
#                           /posix/bin/lsdir
# https://crystalfaeries.net/posix/bin/lsdir
# celeste:crystalfaery LSDIR 2020-06-12 20:05:42+00:00
# list filenames sorted by width, or
# with -r option in reverse order.
# NOTE: WE ONLY work on the CURRENT WORKING DIRECTORY!
let help=7
case $# in
0 )	# no options or arguments
	ls -Fd .??* * | awk '{print length, $0}' | sort -n  | cut -f2- -d' '
	exit $?
	;;
* ) case "${1}" in
-v | --version )
	head -n 4 $0 | tail -n 1	1>&2
	exit
	;;
-h | --help )
	head -n $help $0		1>&2
	exit
	;;
-r)
	ls -Fd .??* * | awk '{print length, $0}' | sort -nr | cut -f2- -d' '
	exit $?
	;;
* )	echo "$0 does not cognize ${1}"	1>&2
	exit -1
	;;
    esac
    ;;
esac
exit $?
