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: libs/, man/, /, modules/
Date: Mon, 02 Sep 2019 11:48:06
Message-Id: 1567419945.0905154aae24c2f17b137b45f5a1dd11fb4774fb.ulm@gentoo
1 commit: 0905154aae24c2f17b137b45f5a1dd11fb4774fb
2 Author: Ulrich Müller <ulm <AT> gentoo <DOT> org>
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=0905154a
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> gentoo.org>
19
20 ChangeLog | 10 ++++++++++
21 libs/editor-variable.bash.in | 47 ++++++++++++++++++++++++++++----------------
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, 56 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..a3bfdc7 100644
49 --- a/libs/editor-variable.bash.in
50 +++ b/libs/editor-variable.bash.in
51 @@ -21,26 +21,49 @@
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 + if find_in_path "${file}"; then
94 + [[ ${i} == *:* ]] && echo "${i%%:*}" || echo "${file}"
95 + fi
96 done
97
98 # also output the current value if it isn't in our list
99 cur=$(read_env_value)
100 - [[ -n ${cur} && ${EDITOR_LIST} != *:* && -f ${ROOT}${cur} ]] \
101 + [[ -n ${cur} && ${EDITOR_LIST} != *:* ]] \
102 && ! has "${cur#${EPREFIX}}" ${EDITOR_LIST} \
103 + && find_in_path "${cur}" \
104 && echo "${cur}"
105 }
106
107 @@ -130,18 +153,8 @@ do_set() {
108 fi
109
110 if [[ ${EDITOR_LIST} != *:* ]]; then
111 - # is the target an absolute path? if not, try to find it
112 - if [[ ${target} != /* ]]; then
113 - local ifs_save=${IFS} IFS=:
114 - for dir in ${EDITOR_PATH-/bin:/usr/bin}; do
115 - [[ -f ${EROOT}${dir}/${target} ]] || continue
116 - target=${EPREFIX}${dir}/${target}
117 - break
118 - done
119 - IFS=${ifs_save}
120 - fi
121 # target is valid if it's a path to an existing binary
122 - [[ ${target} == /* && -f ${ROOT}${target} ]] \
123 + find_in_path "${target}" \
124 || die -q "Target \"${target}\" doesn't appear to be valid!"
125 else
126 # target is valid only if it's in our list
127
128 diff --git a/man/editor.eselect.5 b/man/editor.eselect.5
129 index 218500a..8a296f1 100644
130 --- a/man/editor.eselect.5
131 +++ b/man/editor.eselect.5
132 @@ -2,7 +2,7 @@
133 .\" Copyright 2009-2019 Gentoo Authors
134 .\" Distributed under the terms of the GNU GPL version 2 or later
135 .\"
136 -.TH editor.eselect 5 "September 2012" "Gentoo Linux" eselect
137 +.TH editor.eselect 5 "September 2019" "Gentoo Linux" eselect
138 .SH NAME
139 editor.eselect \- The EDITOR management module for Gentoo's eselect
140 .SH SYNOPSIS
141 @@ -32,9 +32,9 @@ variable.
142 .br
143 Available targets for the EDITOR variable:
144 .br
145 - [1] /bin/nano *
146 - [2] /usr/bin/emacs
147 - [3] /usr/bin/vi
148 + [1] nano *
149 + [2] emacs
150 + [3] vi
151 [ ] (free form)
152 .SH ACTION: SET
153 .B eselect editor set
154 @@ -46,11 +46,11 @@ variable in the system profile.
155 .I target
156 can be either an identification number given by
157 .B eselect editor list
158 -or the name of an installed text editor.
159 +or the name (with or without full path) of an installed text editor.
160
161 # eselect editor set emacs
162 .br
163 -Setting EDITOR to /usr/bin/emacs ...
164 +Setting EDITOR to emacs ...
165 .br
166 Run ". /etc/profile" to update the variable in your shell.
167 .SH ACTION: SHOW
168 @@ -64,7 +64,7 @@ variable in the system profile.
169 .br
170 EDITOR variable in profile:
171 .br
172 - /usr/bin/emacs
173 + emacs
174 .SH ACTION: UPDATE
175 .B eselect editor update
176 .br
177
178 diff --git a/man/pager.eselect.5 b/man/pager.eselect.5
179 index a0d1052..e5ac4c6 100644
180 --- a/man/pager.eselect.5
181 +++ b/man/pager.eselect.5
182 @@ -2,7 +2,7 @@
183 .\" Copyright 2009-2019 Gentoo Authors
184 .\" Distributed under the terms of the GNU GPL version 2 or later
185 .\"
186 -.TH pager.eselect 5 "June 2016" "Gentoo Linux" eselect
187 +.TH pager.eselect 5 "September 2019" "Gentoo Linux" eselect
188 .SH NAME
189 pager.eselect \- The PAGER management module for Gentoo's eselect
190 .SH SYNOPSIS
191 @@ -32,8 +32,8 @@ variable.
192 .br
193 Available targets for the PAGER variable:
194 .br
195 - [1] /usr/bin/less
196 - [2] /bin/more *
197 + [1] less
198 + [2] more *
199 [ ] (free form)
200 .SH ACTION: SET
201 .B eselect pager set
202 @@ -45,11 +45,12 @@ variable in the system profile.
203 .I target
204 can be either an identification number given by
205 .B eselect pager list
206 -or the name of an installed terminal pager program.
207 +or the name (with or without full path) of an installed terminal pager
208 +program.
209
210 # eselect pager set 2
211 .br
212 -Setting PAGER to /usr/bin/less ...
213 +Setting PAGER to less ...
214 .br
215 Run ". /etc/profile" to update the variable in your shell.
216 .SH ACTION: SHOW
217 @@ -63,7 +64,7 @@ variable in the system profile.
218 .br
219 PAGER variable in profile:
220 .br
221 - /usr/bin/less
222 + less
223 .SH ACTION: UPDATE
224 .B eselect pager update
225 .br
226
227 diff --git a/modules/editor.eselect b/modules/editor.eselect
228 index 1bee5ac..835b9e8 100644
229 --- a/modules/editor.eselect
230 +++ b/modules/editor.eselect
231 @@ -5,12 +5,7 @@
232 EDITOR_VAR="EDITOR"
233 EDITOR_ENVFILE="/etc/env.d/99editor"
234 # list of most common cases only
235 -EDITOR_LIST="/bin/nano
236 - /bin/ed
237 - /usr/bin/emacs
238 - /usr/bin/ex
239 - /usr/bin/vi
240 - /usr/bin/xemacs"
241 +EDITOR_LIST="nano ed emacs ex vi xemacs"
242
243 inherit editor-variable
244
245
246 diff --git a/modules/pager.eselect b/modules/pager.eselect
247 index d0ff910..8c5d7fd 100644
248 --- a/modules/pager.eselect
249 +++ b/modules/pager.eselect
250 @@ -4,7 +4,7 @@
251
252 EDITOR_VAR="PAGER"
253 EDITOR_ENVFILE="/etc/env.d/99pager"
254 -EDITOR_LIST="/usr/bin/less /bin/more /usr/bin/most"
255 +EDITOR_LIST="less more most"
256
257 inherit editor-variable