home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] least: bash pager hack

* Patrick Smith <patsmith [ at ] pobox [ dot ] com> [050818 01:22]:
> I don't claim to be a guru, but here's one attempt...
> 
> function least() {
> if [ -n "$*" ]; then

cool.

> 	cat "$@" | least

I specifically did not use quotes around the $@ passed to cat so that
least would work with multiple arguments.  Will an unquoted $@ cause me
problems when filenames contains spcaes?

> 	return $?
> fi
> 
> case "$LINES" in
> 	'') LINES=20 ;;
> 	*[^0-9]*) LINES=20 ;;
> esac

no arguments there.

> start="$(head -$(($LINES + 1)))"

IIRC, newer versions of 'head' don't support -<cont> so -n<count> is
required.

> if [ $(printf "%s" "$start" | wc -l) -le $LINES ]; then
> 	printf "%s" "$start"
> else
> 	( printf "%s" "%start"; cat; ) | $PAGER
> fi
> }

Thanks, you've given me some ideas.

-- 
				WebSig: http://www.jukie.net/~bart/sig/

Attachment: signature.asc
Description: Digital signature