Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-apps/less/files/
Date: Sun, 15 Sep 2019 07:53:06
Message-Id: 1568533859.741f5ec1e6d6668a9e51d292cc5c1e34a4f905c2.vapier@gentoo
1 commit: 741f5ec1e6d6668a9e51d292cc5c1e34a4f905c2
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Sun Sep 15 07:46:01 2019 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Sun Sep 15 07:50:59 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=741f5ec1
7
8 sys-apps/less: lesspipe: minor improvements
9
10 * Add/update copyright/license headers.
11 * Test whether LESSDEBUG is set rather than its value
12 * Fix `stat` usage on pseudo paths (e.g. URIs) & names that start with -
13 * Add a .json print handler via python
14 * Process https:// URIs like http://
15 * Try elinks in addition to & before other CLI browsers
16 * Tweak quoting in a few places as shellcheck highlighted
17 * Check $# -eq 0 so we don't treat "" as missing arguments
18 * Don't run lesspipe twice when it fails & LESSDEBUG is enabled
19
20 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>
21
22 sys-apps/less/files/lesspipe.sh | 29 ++++++++++++++++-------------
23 1 file changed, 16 insertions(+), 13 deletions(-)
24
25 diff --git a/sys-apps/less/files/lesspipe.sh b/sys-apps/less/files/lesspipe.sh
26 index 66078850cbd..68ec0f67926 100755
27 --- a/sys-apps/less/files/lesspipe.sh
28 +++ b/sys-apps/less/files/lesspipe.sh
29 @@ -1,11 +1,13 @@
30 #!/bin/bash
31 -#
32 +# Copyright 1999-2019 Gentoo Authors
33 +# Distributed under the terms of the GNU General Public License v2
34 +
35 # Preprocessor for 'less'. Used when this environment variable is set:
36 # LESSOPEN="|lesspipe %s"
37
38 # TODO: handle compressed files better
39
40 -[[ -n ${LESSDEBUG} ]] && set -x
41 +[[ -n ${LESSDEBUG+set} ]] && set -x
42
43 trap 'exit 0' PIPE
44
45 @@ -64,8 +66,9 @@ lesspipe() {
46 ls -alF -- "$1"
47 return
48 elif [[ ! -f $1 ]] ; then
49 - stat "$1"
50 - return
51 + # Only return if the stat passes. This is needed to handle pseudo
52 + # arguments like URIs.
53 + stat -- "$1" && return
54 fi
55
56 case "${match}" in
57 @@ -104,10 +107,11 @@ lesspipe() {
58 *.doc) antiword "$1" || catdoc "$1" ;;
59 *.rtf) unrtf --nopict --text "$1" ;;
60 *.conf|*.txt|*.log) ;; # force less to work on these directly #150256
61 + *.json) python -mjson.tool "$1" ;;
62
63 ### URLs ###
64 - ftp://*|http://*|*.htm|*.html)
65 - for b in links2 links lynx ; do
66 + ftp://*|http://*|https://|*.htm|*.html)
67 + for b in elinks links2 links lynx ; do
68 ${b} -dump "$1" && exit 0
69 done
70 html2text -style pretty "$1"
71 @@ -120,7 +124,7 @@ lesspipe() {
72 *.tar.lzma|*.tar.xz)
73 ${DECOMPRESSOR} -- "$1" | tar tvvf -;;
74 *.tbz2|*.tbz|*.tgz|*.tlz|*.txz)
75 - lesspipe "$1" "$1".tar.${1##*.t} ;;
76 + lesspipe "$1" "$1.tar.${1##*.t}" ;;
77
78 ### Misc archives ###
79 *.bz2|\
80 @@ -207,7 +211,7 @@ lesspipe() {
81 *)
82 case $(( recur++ )) in
83 # Maybe we didn't match due to case issues ...
84 - 0) lesspipe "$1" "$(echo $1 | LC_ALL=C tr '[:upper:]' '[:lower:]')" ;;
85 + 0) lesspipe "$1" "$(echo "$1" | LC_ALL=C tr '[:upper:]' '[:lower:]')" ;;
86
87 # Maybe we didn't match because the file is named weird ...
88 1) lesspipe_file "$1" ;;
89 @@ -241,12 +245,12 @@ lesspipe() {
90 esac
91 }
92
93 -if [[ -z $1 ]] ; then
94 +if [[ $# -eq 0 ]] ; then
95 echo "Usage: lesspipe <file>"
96 elif [[ $1 == "-V" || $1 == "--version" ]] ; then
97 cat <<-EOF
98 lesspipe (git)
99 - Copyright 2001-2016 Gentoo Foundation
100 + Copyright 1999-2019 Gentoo Authors
101 Mike Frysinger <vapier@g.o>
102 (with plenty of ideas stolen from other projects/distros)
103
104 @@ -275,7 +279,6 @@ elif [[ $1 == "-h" || $1 == "--help" ]] ; then
105 EOF
106 else
107 recur=0
108 - [[ -n ${LESSDEBUG} ]] \
109 - && lesspipe "$1" \
110 - || lesspipe "$1" 2> /dev/null
111 + [[ -z ${LESSDEBUG+set} ]] && exec 2>/dev/null
112 + lesspipe "$1"
113 fi