new crontab for renewing letsencrypt
[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   local 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   else
19     # drop the value and emptiness will mean don't show code.
20     unset code_view_flag
21   fi
22
23   if [ ! -z "$code_view_flag" ]; then
24     # establish a pipe for less to see our beloved syntax highlighting.
25     export LESSOPEN="| source-highlight -f esc -o STDOUT -i %s"
26   fi
27
28
29   # run the source highlighter first if needed.
30   /bin/less -r "${@}" 
31 }
32
33 ##############
34
35 # now that we have our function, just use it on all the input parameters.
36 # this is done to avoid adding yet another function to the core.
37 lesser "${@}" 
38