cleaned up a bit and readied for general use
[feisty_meow.git] / scripts / files / lesser.sh
1 #!/bin/bash
2
3 # runs the less command but with some additional options.
4 #
5 # we always pass the raw flag (-r) so our special formatting is not lost.
6 # this may not be the best choice for some text terminals.
7 #
8 # there is also a "code" option added (-c) that formats the incoming data as
9 # if it were source code before showing the output.  this works great on files
10 # that are actually recognized as source code, and not so great on other
11 # things like simple lists or error output.
12 function lesser()
13 {
14   code_view_flag="$1"
15   if [ "$code_view_flag" == "-c" ]; then
16     # saw the 'code' flag, which means show the file with source highlighting.
17     shift
18 #echo saw the code flag
19
20   else
21     # drop the value and emptiness will mean don't show code.
22     unset code_view_flag
23   fi
24
25   if [ ! -z "$code_view_flag" ]; then
26     # establish a pipe for less to see our beloved syntax highlighting.
27     export LESSOPEN="| source-highlight -f esc -o STDOUT -i %s"
28   fi
29
30
31   # run the source highlighter first if needed.
32   /bin/less -r "${@}" 
33
34 #hmmm, will we need to iterate on the input array to get this right?
35
36 #hmmm: do we need to protect above from space hosings?
37 #  done, maybe.  if this still works for multiple parms...
38
39 }
40
41 # now that we have our function, just use it on all the input parameters.
42 # this is done to avoid adding yet another function to the core.
43 lesser "${@}" 
44
45