Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Accept usage of different pagers #12

Open
wants to merge 1 commit into from

2 participants

Vladimir Chizhov Dave Eddy
Vladimir Chizhov

Accept usage of some system-wide set (by $PAGER) pagers:

  • less (default)
  • more
  • vimpager

If the unsupported pager is set - it will be automatically replaced by
the default one.

Partially closes issue #8. Mentioned there most pager cannot be supported easily.

Vladimir Chizhov mirlord Accept usage of some system-wide set (by $PAGER) pagers:
* less (default)
* more
* vimpager

If the unsupported pager is set - it will be automatically replaced by
the default one.
c966998
Vladimir Chizhov

most can be easily supported, as I can see.
The only problem, that the default configuration file (mad.conf) uses a non standard control-sequence: 90m. most's capabilities are limited to smth like this: http://wiki.bash-hackers.org/scripting/terminalcodes

I can change the default config, or add a special one and use it with most.

What would be the best option?

Vladimir Chizhov mirlord referenced this pull request
Closed

Mad patch 1 #13

Dave Eddy

I'm checking this out from your comment on #12. This implementation is definitely better as it is pager-aware, however the eval statement doesn't sit well with me. I see the reasoning behind it, and in a perfect world we could assume everybody has bash v4 and associative arrays, but that's not the case. I would recommend an implementation like this.

# Check env, default to less
local pager_cmd=${PAGER:-less}
local pager_opt=

# Command specific options
case "$pager_cmd" in
    less) pager_opt='-R';;
    more) pager_opt='';;
    most) pager_cmd='less';; # most not supported
    *) pager_opt='';;
esac

foo | "$pager_cmd" $pager_opt

In the above example we have $pager_cmd that is set to $PAGER, and will default to less. Then we case-statement over the $pager_cmd variable to generate command-specific options. Having 'more' and '*' in the case statement is redundant, but they are there to illustrate the point.

In the call to foo at the bottom, $pager_cmd is quoted to avoid word-splitting by bash, but $pager_opt is left unquoted so the options will expand as though they were typed on the command line.

Vladimir Chizhov

Not a problem to reimplement.
But maintainer's decision about most and [90m formatting escape-sequence required to do it as 100% ready for another pull-request :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 20, 2012
  1. Vladimir Chizhov

    Accept usage of some system-wide set (by $PAGER) pagers:

    mirlord authored
    * less (default)
    * more
    * vimpager
    
    If the unsupported pager is set - it will be automatically replaced by
    the default one.
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 1 deletion.
  1. +19 −1 bin/mad
20 bin/mad
View
@@ -79,6 +79,24 @@ display_file() {
local strong=$(get strong)
local em=$(get em)
+ # Not any pager is supported, only the most popular:
+ # - more
+ local more_options=""
+ # - less
+ local less_options="-R"
+ # - vimpager
+ local vimpager_options=""
+ # the others may be supported or not, excluding the following,
+ # known as unsupported:
+ # - most
+ local pagers_unsupported="\(most\)" # sed regexp
+
+ # choose pager
+ local pager_default="less"
+ local pager_cmd=${PAGER:-${pager_default}}
+ # Replace unsupported pagers with the default one.
+ pager_cmd=$(echo ${pager_cmd} | sed "s|${pagers_unsupported}|${pager_default}|")
+
cat $1 \
| perl -pe "
s|^#+ *(.+)|\e[$heading\1\e[0m|g; \
@@ -90,7 +108,7 @@ display_file() {
s| (.+)| \e[$code\1\e[0m|g; \
s|<(.+?)>||g; \
s|^| |;" \
- | less -R
+ | ${pager_cmd} $(eval "echo \$${pager_cmd}_options")
exit
}
Something went wrong with that request. Please try again.