Gentoo Archives: gentoo-commits

From: "Ulrich Müller" <ulm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/eselect:master commit in: /, man/, modules/, libs/
Date: Mon, 02 Sep 2019 10:49:22
Message-Id: 1567419945.7dd4e2a14dabdc7f2358c1d5d690e4c8dabfd79c.ulm@gentoo
1 commit: 7dd4e2a14dabdc7f2358c1d5d690e4c8dabfd79c
2 Author: Ulrich Müller <ulm <AT> kph <DOT> uni-mainz <DOT> de>
3 AuthorDate: Mon Sep 2 10:25:45 2019 +0000
4 Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org>
5 CommitDate: Mon Sep 2 10:25:45 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/eselect.git/commit/?id=7dd4e2a1
7
8 Support relative pathnames in editor-variable library.
9
10 * libs/editor-variable.bash.in (find_in_path): New function, looks
11 up its first argument in EDITOR_PATH, and tests if it exists.
12 (find_targets, do_set): Use it.
13 * modules/pager.eselect (EDITOR_LIST):
14 * modules/editor.eselect (EDITOR_LIST): Don't use absolute paths.
15 * man/editor.eselect.5:
16 * man/pager.eselect.5: Update.
17
18 Signed-off-by: Ulrich Müller <ulm <AT> kph.uni-mainz.de>
19
20 ChangeLog | 10 ++++++++++
21 libs/editor-variable.bash.in | 45 +++++++++++++++++++++++++++-----------------
22 man/editor.eselect.5 | 14 +++++++-------
23 man/pager.eselect.5 | 13 +++++++------
24 modules/editor.eselect | 7 +------
25 modules/pager.eselect | 2 +-
26 6 files changed, 54 insertions(+), 37 deletions(-)
27
28 diff --git a/ChangeLog b/ChangeLog
29 index 94f8577..cbb6229 100644
30 --- a/ChangeLog
31 +++ b/ChangeLog
32 @@ -1,3 +1,13 @@
33 +2019-09-02 Ulrich Müller <ulm@g.o>
34 +
35 + * libs/editor-variable.bash.in (find_in_path): New function, looks
36 + up its first argument in EDITOR_PATH, and tests if it exists.
37 + (find_targets, do_set): Use it.
38 + * modules/pager.eselect (EDITOR_LIST):
39 + * modules/editor.eselect (EDITOR_LIST): Don't use absolute paths.
40 + * man/editor.eselect.5:
41 + * man/pager.eselect.5: Update.
42 +
43 2019-05-26 Ulrich Müller <ulm@g.o>
44
45 * modules/news.eselect (do_read, do_unread): Allow specification
46
47 diff --git a/libs/editor-variable.bash.in b/libs/editor-variable.bash.in
48 index ac71ecf..a57e51d 100644
49 --- a/libs/editor-variable.bash.in
50 +++ b/libs/editor-variable.bash.in
51 @@ -21,26 +21,47 @@
52 # EDITOR_VAR is the name of the environment variable, e.g. "EDITOR".
53 # EDITOR_ENVFILE is the path to the config file where the variable should be
54 # stored, e.g. "/etc/env.d/99editor". Several modules may share the same file.
55 -# EDITOR_LIST is a space-separated list of available programs (full pathnames)
56 -# e.g. "/bin/nano /usr/bin/emacs /usr/bin/vi". Alternatively, items can be of
57 -# the form "name:/path/to/binary".
58 +# EDITOR_LIST is a space-separated list of available programs (with or without
59 +# full pathname), e.g., "nano emacs /usr/bin/vi". Alternatively, items can be
60 +# of the form "name:/path/to/binary".
61 # EDITOR_PATH (optional) is a colon-separated list of directories where to
62 # search for available programs. Default is "/bin:/usr/bin".
63
64 inherit config
65
66 +# find file in EDITOR_PATH
67 +find_in_path() {
68 + local file=$1
69 +
70 + # do we already have an absolute path?
71 + if [[ ${file} == /* ]]; then
72 + [[ -f ${ROOT}${file} ]]
73 + return
74 + fi
75 +
76 + # try to find it
77 + local IFS=:
78 + for dir in ${EDITOR_PATH-/bin:/usr/bin}; do
79 + [[ -f ${EROOT}${dir}/${file} ]] && return 0
80 + done
81 + return 1
82 +}
83 +
84 # find a list of valid targets
85 find_targets() {
86 - local cur i
87 + local cur i file
88
89 for i in ${EDITOR_LIST}; do
90 - [[ -f ${EROOT}${i#*:} ]] && echo "${EPREFIX}${i%%:*}"
91 + file=${i#*:}
92 + [[ ${file} == /* ]] && file=${EPREFIX}${file}
93 + find_in_path "${file}" && echo "${file}"
94 done
95
96 # also output the current value if it isn't in our list
97 cur=$(read_env_value)
98 - [[ -n ${cur} && ${EDITOR_LIST} != *:* && -f ${ROOT}${cur} ]] \
99 + [[ -n ${cur} && ${EDITOR_LIST} != *:* ]] \
100 && ! has "${cur#${EPREFIX}}" ${EDITOR_LIST} \
101 + && find_in_path "${cur}" \
102 && echo "${cur}"
103 }
104
105 @@ -130,18 +151,8 @@ do_set() {
106 fi
107
108 if [[ ${EDITOR_LIST} != *:* ]]; then
109 - # is the target an absolute path? if not, try to find it
110 - if [[ ${target} != /* ]]; then
111 - local ifs_save=${IFS} IFS=:
112 - for dir in ${EDITOR_PATH-/bin:/usr/bin}; do
113 - [[ -f ${EROOT}${dir}/${target} ]] || continue
114 - target=${EPREFIX}${dir}/${target}
115 - break
116 - done
117 - IFS=${ifs_save}
118 - fi
119 # target is valid if it's a path to an existing binary
120 - [[ ${target} == /* && -f ${ROOT}${target} ]] \
121 + find_in_path "${target}" \
122 || die -q "Target \"${target}\" doesn't appear to be valid!"
123 else
124 # target is valid only if it's in our list
125
126 diff --git a/man/editor.eselect.5 b/man/editor.eselect.5
127 index 218500a..8a296f1 100644
128 --- a/man/editor.eselect.5
129 +++ b/man/editor.eselect.5
130 @@ -2,7 +2,7 @@
131 .\" Copyright 2009-2019 Gentoo Authors
132 .\" Distributed under the terms of the GNU GPL version 2 or later
133 .\"
134 -.TH editor.eselect 5 "September 2012" "Gentoo Linux" eselect
135 +.TH editor.eselect 5 "September 2019" "Gentoo Linux" eselect
136 .SH NAME
137 editor.eselect \- The EDITOR management module for Gentoo's eselect
138 .SH SYNOPSIS
139 @@ -32,9 +32,9 @@ variable.
140 .br
141 Available targets for the EDITOR variable:
142 .br
143 - [1] /bin/nano *
144 - [2] /usr/bin/emacs
145 - [3] /usr/bin/vi
146 + [1] nano *
147 + [2] emacs
148 + [3] vi
149 [ ] (free form)
150 .SH ACTION: SET
151 .B eselect editor set
152 @@ -46,11 +46,11 @@ variable in the system profile.
153 .I target
154 can be either an identification number given by
155 .B eselect editor list
156 -or the name of an installed text editor.
157 +or the name (with or without full path) of an installed text editor.
158
159 # eselect editor set emacs
160 .br
161 -Setting EDITOR to /usr/bin/emacs ...
162 +Setting EDITOR to emacs ...
163 .br
164 Run ". /etc/profile" to update the variable in your shell.
165 .SH ACTION: SHOW
166 @@ -64,7 +64,7 @@ variable in the system profile.
167 .br
168 EDITOR variable in profile:
169 .br
170 - /usr/bin/emacs
171 + emacs
172 .SH ACTION: UPDATE
173 .B eselect editor update
174 .br
175
176 diff --git a/man/pager.eselect.5 b/man/pager.eselect.5
177 index a0d1052..e5ac4c6 100644
178 --- a/man/pager.eselect.5
179 +++ b/man/pager.eselect.5
180 @@ -2,7 +2,7 @@
181 .\" Copyright 2009-2019 Gentoo Authors
182 .\" Distributed under the terms of the GNU GPL version 2 or later
183 .\"
184 -.TH pager.eselect 5 "June 2016" "Gentoo Linux" eselect
185 +.TH pager.eselect 5 "September 2019" "Gentoo Linux" eselect
186 .SH NAME
187 pager.eselect \- The PAGER management module for Gentoo's eselect
188 .SH SYNOPSIS
189 @@ -32,8 +32,8 @@ variable.
190 .br
191 Available targets for the PAGER variable:
192 .br
193 - [1] /usr/bin/less
194 - [2] /bin/more *
195 + [1] less
196 + [2] more *
197 [ ] (free form)
198 .SH ACTION: SET
199 .B eselect pager set
200 @@ -45,11 +45,12 @@ variable in the system profile.
201 .I target
202 can be either an identification number given by
203 .B eselect pager list
204 -or the name of an installed terminal pager program.
205 +or the name (with or without full path) of an installed terminal pager
206 +program.
207
208 # eselect pager set 2
209 .br
210 -Setting PAGER to /usr/bin/less ...
211 +Setting PAGER to less ...
212 .br
213 Run ". /etc/profile" to update the variable in your shell.
214 .SH ACTION: SHOW
215 @@ -63,7 +64,7 @@ variable in the system profile.
216 .br
217 PAGER variable in profile:
218 .br
219 - /usr/bin/less
220 + less
221 .SH ACTION: UPDATE
222 .B eselect pager update
223 .br
224
225 diff --git a/modules/editor.eselect b/modules/editor.eselect
226 index 1bee5ac..835b9e8 100644
227 --- a/modules/editor.eselect
228 +++ b/modules/editor.eselect
229 @@ -5,12 +5,7 @@
230 EDITOR_VAR="EDITOR"
231 EDITOR_ENVFILE="/etc/env.d/99editor"
232 # list of most common cases only
233 -EDITOR_LIST="/bin/nano
234 - /bin/ed
235 - /usr/bin/emacs
236 - /usr/bin/ex
237 - /usr/bin/vi
238 - /usr/bin/xemacs"
239 +EDITOR_LIST="nano ed emacs ex vi xemacs"
240
241 inherit editor-variable
242
243
244 diff --git a/modules/pager.eselect b/modules/pager.eselect
245 index d0ff910..8c5d7fd 100644
246 --- a/modules/pager.eselect
247 +++ b/modules/pager.eselect
248 @@ -4,7 +4,7 @@
249
250 EDITOR_VAR="PAGER"
251 EDITOR_ENVFILE="/etc/env.d/99pager"
252 -EDITOR_LIST="/usr/bin/less /bin/more /usr/bin/most"
253 +EDITOR_LIST="less more most"
254
255 inherit editor-variable