X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Ffiles%2Flesser.sh;fp=scripts%2Ffiles%2Flesser.sh;h=f6674f1364880583496ede3baa4281de51a21395;hb=7b39f7e279005c8466ef508220a532ce2aa4abf8;hp=66b7732ef2bd5e4529c3a38db77c2cd618db15b8;hpb=3fbd372b35b15a19fb171d5ae34294ff7b1e6485;p=feisty_meow.git diff --git a/scripts/files/lesser.sh b/scripts/files/lesser.sh index 66b7732e..f6674f13 100644 --- a/scripts/files/lesser.sh +++ b/scripts/files/lesser.sh @@ -2,19 +2,23 @@ # 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() { 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 + + # 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. unset code_view_flag @@ -25,9 +29,8 @@ function lesser() export LESSOPEN="| source-highlight -f esc -o STDOUT -i %s" fi - # run the source highlighter first if needed. - /bin/less -r "${@}" + /bin/less $EXTRA_OPTIONS "${@}" } ##############