#!/bin/ksh
#
# $Revision: 1.5 $ $Date: 2012-07-26 16:39:44-04 $
# $Source: /home/vogelke/bin/RCS/lst,v $
# $Host: sys7.com $
# $UUID: e8750981-a381-3381-b041-20097dff229a $
#
#<lst: sort files by size, name, time, etc.
# Based on http://www.us-webmasters.com/FreeBSD/Configuration/Shell/
# Updated for use with GNU version of ls, coreutils-6.9 or greater.

# install: for x in lsl lslm lsn lsnm lss lssm lstm; do ln lst $x; done

PATH=/usr/local/bin:/bin:/usr/bin; export PATH
: ${PAGER:=less};                  export PAGER
tag=${0##*/}

runls () {
    ls -ablptF --time-style='+%d-%b-%Y %T' ${1+"$@"}
}

clean () {
    sed -e '/^total /d'
}

case "$tag" in
    # LiSt files with Largest last
    lsl)  runls ${1+"$@"} | sort -k 5,5n | clean ;;

    # LiSt files, Largest first, a page at a tiMe
    lslm) runls ${1+"$@"} | sort -k 5,5rn | clean | $PAGER ;;

    # LiSt files sorted by name
    lsn)  runls ${1+"$@"} | sort -k 8,8 | clean ;;

    # LiSt files sorted by Name a page at a tiMe
    lsnm) runls ${1+"$@"} | sort -k 8,8 | clean | $PAGER ;;

    # LiSt files with Smallest shown last
    lss)  runls ${1+"$@"} | sort -k 5,5rn | clean ;;

    # LiSt files a page at a time with the SMallest shown first
    lssm) runls ${1+"$@"} | sort -k 5,5n | clean | $PAGER ;;

    # LiSt files, newly modified (Time) shown last
    lst)  runls -r ${1+"$@"} | clean ;;

    # LiSt files a page at a time, newly Modified (Time) shown first
    lstm) runls ${1+"$@"} | clean | $PAGER ;;
esac

exit 0
