Skip to content

Commit

Permalink
change default behaviour if lesspipe.sh is named differently
Browse files Browse the repository at this point in the history
  • Loading branch information
wofr06 committed Feb 19, 2024
1 parent a215a5c commit 27bb994
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ the author by email.
```
If `lesspipe.sh` is not in the UNIX search path or if the wrong `lesspipe.sh` is
found in the search path, then the full path to `lesspipe.sh` should be given
in the above commands.
in the above commands. The above commands work only in the described manner
if the file name is lesspipe.sh.

If it is installed under a different name then calling it without an argument
will work as a filter with LESSQUIET set and expecting input from STDIN.

The command to set **LESSOPEN** can also be displayed by calling `lesspipe.sh`
without arguments. This can even be used to set **LESSOPEN** directly:
Expand Down
7 changes: 6 additions & 1 deletion lesspipe.1
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ This can even be used to set \fBLESSOPEN\fP directly:
.I lesspipe.sh|source /dev/stdin
(zsh)
.RE
The above commands work only in the described manner if the file name is
\fBlesspipe.sh\fP.
If it is installed under a different name then calling it without an argument
will work as a filter with \fBLESSQUIET\fP set and expecting input from STDIN.
.PP
Having set the environment variable as described above, \fBless\fP
will then display textual information for a wide range of file formats.
:will then display textual information for a wide range of file formats.
.PP
The filter is normally not called if input is piped to less as in
.RS
Expand Down
9 changes: 7 additions & 2 deletions lesspipe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ if [[ $LESSOPEN == *\|-* && $1 == - ]]; then
nexttmp >/dev/null
fi

if [[ -z "$1" ]]; then
if [[ -z "$1" && "$0" == */lesspipe.sh ]]; then
[[ "$0" == /* ]] || pat=$(pwd)/
if [[ "$SHELL" == *csh ]]; then
echo "setenv LESSOPEN \"|$pat$0 %s\""
Expand All @@ -843,5 +843,10 @@ else
elif has_cmd lessfilter; then
lessfilter "$1" && exit 0
fi
show "$@"
if [[ -z "$1" ]]; then
LESSQUIET=1
show -
else
show "$@"
fi
fi

0 comments on commit 27bb994

Please sign in to comment.