Skip to content

Commit d2682da

Browse files
committed
implement passthrough commandline options #238
Add the --passthrough, --force-passthrough and --no-passthrough commandline options. Document them in --help and in the markdown docs. Update scripts/pandoc-sh to account for the -S option no longer being available in newer versions. Update the markdown_src/ files from an earlier PR and regenerate the markdown/ files.
1 parent 826064f commit d2682da

5 files changed

Lines changed: 82 additions & 15 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ man/%.1: markdown_src/%.md
263263
@if command -v pandoc >/dev/null; then \
264264
echo 'generating $@'; \
265265
${MKPATH} `dirname '$@'` 2>/dev/null || true; \
266-
${PANDOC} -Ss -f markdown_github $< -o $@; \
266+
${PANDOC} -s -f markdown_github $< -o $@; \
267267
else \
268268
if [ ! -r docs-warn-stamp ]; then \
269269
echo >&2; \
@@ -283,7 +283,7 @@ html/%.html: %.md.work
283283
@if command -v pandoc >/dev/null; then \
284284
echo 'generating $@'; \
285285
${MKPATH} `dirname '$@'` 2>/dev/null || true; \
286-
${PANDOC} -Ss --toc -f markdown_github $< -o $@; \
286+
${PANDOC} -s --toc -f markdown_github $< -o $@; \
287287
rm -f $<; \
288288
else \
289289
if [ ! -r docs-warn-stamp ]; then \

markdown/vimpager.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
- [--cmd cmd](#--cmd-cmd)
2121
- [-u vimrc](#-u-vimrc)
2222
- [-s](#-s)
23+
- [--passthrough](#--passthrough)
24+
- [--force-passthrough](#--force-passthrough)
25+
- [--no-passthrough](#--no-passthrough)
2326
- [-x](#-x)
2427
- [ANSI ESCAPE SEQUENCES AND OVERSTRIKES](#ansi-escape-sequences-and-overstrikes)
2528
- [PASSTHROUGH MODE](#passthrough-mode)
@@ -67,9 +70,9 @@ cd vimpager
6770
sudo make install-deb
6871
```
6972

70-
To just build the `.deb` use `make build-deb` instead.
73+
To just build the '.deb' use `make build-deb` instead.
7174

72-
Otherwise use `make install`:
75+
Otherwise use 'make install':
7376

7477
```bash
7578
git clone git://github.com/rkitover/vimpager
@@ -86,8 +89,8 @@ The following make settings are supported at `make install` time:
8689
| prefix | prefix for writing files, e.g. for GNU stow |
8790
| POSIX_SHELL | POSIX shell to use to run the scripts |
8891

89-
Note, you should `make clean` before modifying these make settings, as the `install` make target does not account for
90-
their change (when e.g. "configuring" vimpager; vimpager.configured).
92+
**NOTE:** you should `make clean` before modifying these make settings, as the
93+
'install' make target does not account for their change.
9194

9295
If you got vimpager from the vim.org scripts section, just put it
9396
somewhere in your PATH, e.g.:
@@ -372,6 +375,21 @@ Use alternate .vimrc or .vimpagerrc.
372375
Squeeze blank lines into a single blank line. GNU man passes this option to
373376
/usr/bin/pager.
374377

378+
## --passthrough
379+
380+
If files fit on the screen, print them with syntax highlighting using vimcat
381+
instead of invoking the pager.
382+
383+
## --force-passthrough
384+
385+
Always print files with syntax highlighting to the terminal instead of invoking
386+
the pager, regardless of whether they fit on the screen.
387+
388+
## --no-passthrough
389+
390+
Never print files with syntax highlighting to the terminal with vimcat, always
391+
invoke the pager.
392+
375393
## -x
376394

377395
Enable debugging output for the shell script part of vimpager.

markdown_src/vimpager.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ cd vimpager
3737
sudo make install-deb
3838
```
3939

40-
Otherwise use 'make install' instead:
40+
To just build the '.deb' use `make build-deb` instead.
41+
42+
Otherwise use 'make install':
4143

4244
```bash
4345
git clone git://github.com/rkitover/vimpager
@@ -54,6 +56,9 @@ The following make settings are supported at `make install` time:
5456
| prefix | prefix for writing files, e.g. for GNU stow |
5557
| POSIX_SHELL | POSIX shell to use to run the scripts |
5658

59+
**NOTE:** you should `make clean` before modifying these make settings, as the
60+
'install' make target does not account for their change.
61+
5762
If you got vimpager from the vim.org scripts section, just put it
5863
somewhere in your PATH, e.g.:
5964

@@ -337,6 +342,21 @@ Use alternate .vimrc or .vimpagerrc.
337342
Squeeze blank lines into a single blank line. GNU man passes this option to
338343
/usr/bin/pager.
339344

345+
## --passthrough
346+
347+
If files fit on the screen, print them with syntax highlighting using vimcat
348+
instead of invoking the pager.
349+
350+
## --force-passthrough
351+
352+
Always print files with syntax highlighting to the terminal instead of invoking
353+
the pager, regardless of whether they fit on the screen.
354+
355+
## --no-passthrough
356+
357+
Never print files with syntax highlighting to the terminal with vimcat, always
358+
invoke the pager.
359+
340360
## -x
341361

342362
Enable debugging output for the shell script part of vimpager.

scripts/pandoc-sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,29 @@ if ! ( pandoc --help | grep markdown_github >/dev/null ); then
3131
old_pandoc=1
3232
fi
3333

34+
use_smart=
35+
# newer pandoc does not support -S
36+
if ! (pandoc --help | grep -- -S); then
37+
use_smart=1
38+
fi
39+
40+
3441
first_arg=1
3542
for arg in "$@"; do
3643
[ $first_arg -eq 1 ] && set -- && first_arg=0
3744

38-
if [ "$arg" = markdown_github ]; then
45+
if [ "$arg" = "-f" ]; then
46+
if [ -z "$use_smart" ]; then
47+
set -- "$@" -S -f
48+
else
49+
set -- "$@" -f
50+
fi
51+
elif [ "$arg" = markdown_github ]; then
3952
if [ $old_pandoc -eq 1 ]; then
4053
set -- "$@" markdown
41-
else
54+
elif [ -n "$use_smart" ]; then
55+
set -- "$@" markdown_github+pandoc_title_block+smart
56+
else
4257
set -- "$@" markdown_github+pandoc_title_block
4358
fi
4459
else

vimpager

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ main() {
5757
fi
5858

5959
# Parse the command line options as early as possible. These variables might be set because of command line options and are thus initialized.
60-
vim_options=
61-
vimrc=
62-
extra_c=
63-
extra_cmd=
64-
line_numbers=0
60+
vim_options= vimrc= extra_c= extra_cmd= line_numbers=0 no_pass_thru=
6561

6662
# Check for certain parameters to pass on to vim (or conceivably do something else)
6763
# Couldn't use getopt or getopts as neither supports options prepended with +
@@ -102,6 +98,19 @@ main() {
10298
shift
10399
squeeze_blank_lines=1
104100
;;
101+
--passthrough)
102+
shift
103+
no_pass_thru=0
104+
;;
105+
--force-passthrough)
106+
shift
107+
no_pass_thru=0
108+
cat_files=1
109+
;;
110+
--no-passthrough)
111+
shift
112+
no_pass_thru=1
113+
;;
105114
--)
106115
shift
107116
break
@@ -466,7 +475,9 @@ read_vim_settings() {
466475
[ "${var#VAL:}" -eq 0 ] && disable_x11=1
467476
;;
468477
3)
469-
[ "${var#VAL:}" -eq 0 ] && no_pass_thru=1
478+
if [ -z "$no_pass_thru" ]; then
479+
[ "${var#VAL:}" -eq 0 ] && no_pass_thru=1
480+
fi
470481
;;
471482
4)
472483
[ "${var#VAL:}" -ne 0 ] && ansiesc_available=1
@@ -628,6 +639,9 @@ With no FILE, or when FILE is -, read standard
628639
+G, + Go to the end of the file.
629640
-N, --LINE-NUMBERS Show line numbers.
630641
-s Squeeze multiple blank lines into one.
642+
---passthrough If files fit on screen, print them with highlighting (DEFAULT.)
643+
---force-passthrough Always print the files with highlighting, don't invoke pager.
644+
---no-passthrough Never print the files, always invoke pager.
631645
--cmd COMMAND Run (n)vim COMMAND before initialization.
632646
-c COMMAND Run (n)vim COMMAND after initialization.
633647
-u FILE Use FILE as the vimrc.

0 commit comments

Comments
 (0)