X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Ffiles%2Flesser.sh;h=16eb3176bd70af0ccc1066faf011f38f80a0700c;hb=6f6781c879a853e5435e20e897ae4e60b4a01fc7;hp=afcc562563198fe034eaa18bf2fba62411eed583;hpb=9dd72bf7c3c75823ba325948fb7b1089ab18b8ec;p=feisty_meow.git diff --git a/scripts/files/lesser.sh b/scripts/files/lesser.sh index afcc5625..16eb3176 100644 --- a/scripts/files/lesser.sh +++ b/scripts/files/lesser.sh @@ -2,20 +2,22 @@ # runs the less command but with some additional options. # -# we always pass the raw flag (-r) so our special formatting is not lost. -# this may not be the best choice for some text terminals. -# -# there is also a "code" option added (-c) that formats the incoming data as -# if it were source code before showing the output. this works great on files -# that are actually recognized as source code, and not so great on other -# things like simple lists or error output. +# there is a "code" option (-c) that formats the incoming data as if it were source code before +# displaying the output. this works great on files that are actually recognized as source code, +# and not so great on other things like simple lists or error output. function lesser() { - code_view_flag="$1" + local code_view_flag="$1" + + EXTRA_OPTIONS= + if [ "$code_view_flag" == "-c" ]; then # saw the 'code' flag, which means show the file with source highlighting. shift -#echo saw the code flag + + # we always pass the raw flag (-r) when in code view mode so special formatting is not lost. + # this may not work for some text terminals. + EXTRA_OPTIONS=-r else # drop the value and emptiness will mean don't show code. @@ -27,14 +29,13 @@ function lesser() export LESSOPEN="| source-highlight -f esc -o STDOUT -i %s" fi -#hmmm, will we need to iterate on the input array to get this right? - # run the source highlighter first if needed. - /bin/less -r "${@}" - -#hmmm: do we need to protect above from space hosings? -#hmmm: done, maybe. if this still works for multiple parms... - + /usr/bin/env less $EXTRA_OPTIONS "${@}" } +############## + +# now that we have our function, just use it on all the input parameters. +# this is done to avoid adding yet another function to the core. +lesser "${@}"