Gentoo Archives: gentoo-commits

From: "Ulrich Mueller (ulm)" <ulm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] eselect r472 - in trunk: . libs modules
Date: Mon, 20 Apr 2009 06:18:36
Message-Id: E1Lvmpu-0007yh-6F@stork.gentoo.org
1 Author: ulm
2 Date: 2009-04-20 06:18:33 +0000 (Mon, 20 Apr 2009)
3 New Revision: 472
4
5 Added:
6 trunk/libs/editor-variable.bash.in
7 trunk/modules/editor.eselect
8 trunk/modules/pager.eselect
9 trunk/modules/visual.eselect
10 Modified:
11 trunk/AUTHORS
12 trunk/ChangeLog
13 trunk/NEWS
14 trunk/libs/Makefile.am
15 trunk/modules/Makefile.am
16 Log:
17 New modules for the EDITOR, VISUAL, and PAGER environment variables.
18
19 Modified: trunk/AUTHORS
20 ===================================================================
21 --- trunk/AUTHORS 2009-04-19 20:45:58 UTC (rev 471)
22 +++ trunk/AUTHORS 2009-04-20 06:18:33 UTC (rev 472)
23 @@ -34,4 +34,5 @@
24 Modules: emacs
25
26 Ulrich Mueller <ulm@g.o>
27 - Modules: ctags, emacs
28 + Modules: ctags, editor, emacs, pager, visual
29 + Libraries: editor-variable
30
31 Modified: trunk/ChangeLog
32 ===================================================================
33 --- trunk/ChangeLog 2009-04-19 20:45:58 UTC (rev 471)
34 +++ trunk/ChangeLog 2009-04-20 06:18:33 UTC (rev 472)
35 @@ -1,3 +1,14 @@
36 +2009-04-20 Ulrich Mueller <ulm@g.o>
37 +
38 + * libs/editor-variable.bash.in:
39 + * modules/editor.eselect:
40 + * modules/visual.eselect:
41 + * modules/pager.eselect: New modules and library, managing the
42 + EDITOR, VISUAL and PAGER environment variables; bug 190216.
43 + * libs/Makefile.am (eselectlibs_SCRIPTS, EXTRA_DIST):
44 + * modules/Makefile.am (safe_scripts): Add the new files.
45 + * NEWS: Mention the new feature.
46 +
47 2009-04-18 Ulrich Mueller <ulm@g.o>
48
49 * modules/rc.eselect (do_delete): Don't die if the script is no
50
51 Modified: trunk/NEWS
52 ===================================================================
53 --- trunk/NEWS 2009-04-19 20:45:58 UTC (rev 471)
54 +++ trunk/NEWS 2009-04-20 06:18:33 UTC (rev 472)
55 @@ -11,6 +11,7 @@
56 - Add a new module, for listing and querying eselect modules.
57 - Allow setting system-wide default dictionary.
58 - Treat 'help' and 'version' options as if they were actions.
59 + - Modules for the EDITOR, VISUAL, and PAGER environment variables.
60
61 1.0.12:
62 Bug fixes:
63
64 Modified: trunk/libs/Makefile.am
65 ===================================================================
66 --- trunk/libs/Makefile.am 2009-04-19 20:45:58 UTC (rev 471)
67 +++ trunk/libs/Makefile.am 2009-04-20 06:18:33 UTC (rev 472)
68 @@ -4,6 +4,7 @@
69 config.bash \
70 core.bash \
71 default.eselect \
72 + editor-variable.eselect \
73 manip.bash \
74 multilib.bash \
75 output.bash \
76 @@ -18,6 +19,7 @@
77 config.bash.in \
78 core.bash.in \
79 default.eselect.in \
80 + editor-variable.eselect.in \
81 manip.bash.in \
82 multilib.bash.in \
83 output.bash.in \
84
85 Added: trunk/libs/editor-variable.bash.in
86 ===================================================================
87 --- trunk/libs/editor-variable.bash.in (rev 0)
88 +++ trunk/libs/editor-variable.bash.in 2009-04-20 06:18:33 UTC (rev 472)
89 @@ -0,0 +1,169 @@
90 +#!/bin/bash
91 +
92 +# Copyright (c) 2009 Gentoo Foundation
93 +# $Id$
94 +# This file is part of the 'eselect' tools framework.
95 +#
96 +# eselect is free software: you can redistribute it and/or modify it under the
97 +# terms of the GNU General Public License as published by the Free Software
98 +# Foundation, either version 2 of the License, or (at your option) any later
99 +# version.
100 +#
101 +# eselect is distributed in the hope that it will be useful, but WITHOUT ANY
102 +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
103 +# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
104 +#
105 +# You should have received a copy of the GNU General Public License along with
106 +# eselect. If not, see <http://www.gnu.org/licenses/>.
107 +
108 +# This library is for managing environment variables like EDITOR or PAGER.
109 +# To use it, you must set the following variables:
110 +#
111 +# EDITOR_VAR is the name of the environment variable, e.g. "EDITOR".
112 +# EDITOR_ENVFILE is the path to the config file where the variable should be
113 +# stored, e.g. "/etc/env.d/99editor". Several modules may share the same file.
114 +# EDITOR_LIST is a space-seperated list of available programs (full pathnames)
115 +# e.g. "/bin/nano /usr/bin/emacs /usr/bin/vi"
116 +# EDITOR_PATH (optional) is a colon-separated list of directories where to
117 +# search for available programs. Default is "/bin:/usr/bin".
118 +
119 +inherit config
120 +
121 +# find a list of valid targets
122 +find_targets() {
123 + local cur targets i
124 + targets=${EDITOR_LIST}
125 + cur=$(read_env_value)
126 +
127 + # also include the current value if it's not already in our list
128 + [[ -n ${cur} ]] && ! has "${cur}" "${targets}" \
129 + && targets="${targets} ${cur}"
130 +
131 + for i in ${targets}; do
132 + [[ -f "${ROOT}${i}" ]] && echo "${i}"
133 + done
134 +}
135 +
136 +# read variable value from config file
137 +read_env_value() {
138 + load_config "${ROOT}${EDITOR_ENVFILE}" "${EDITOR_VAR}"
139 +}
140 +
141 +# write variable to config file
142 +write_env_value() {
143 + [[ -w "${ROOT}${EDITOR_ENVFILE%/*}" ]] \
144 + || die -q "You need root privileges!"
145 + store_config "${ROOT}${EDITOR_ENVFILE}" "${EDITOR_VAR}" "${1}"
146 +}
147 +
148 +### show action ###
149 +
150 +describe_show() {
151 + echo "Show value of the ${EDITOR_VAR} variable in profile"
152 +}
153 +
154 +do_show() {
155 + [[ ${#@} -gt 0 ]] && die -q "Too many parameters"
156 +
157 + local cur=$(read_env_value)
158 + write_list_start "${EDITOR_VAR} variable in profile:"
159 + write_kv_list_entry "${cur:-(none)}"
160 +}
161 +
162 +### list action ###
163 +
164 +describe_list() {
165 + echo "List available targets for the ${EDITOR_VAR} variable"
166 +}
167 +
168 +do_list() {
169 + [[ ${#@} -gt 0 ]] && die -q "Too many parameters"
170 +
171 + local cur targets i
172 + cur=$(read_env_value)
173 + targets=( $(find_targets) )
174 +
175 + write_list_start "Available targets for the ${EDITOR_VAR} variable:"
176 + if [[ -n ${targets[@]} ]]; then
177 + for (( i = 0; i < ${#targets[@]}; i = i + 1 )); do
178 + # Display a star to indicate the currently chosen version
179 + [[ ${targets[i]} = ${cur} ]] \
180 + && targets[i]="${targets[i]} $(highlight '*')"
181 + done
182 + write_numbered_list "${targets[@]}"
183 + fi
184 + write_numbered_list_entry " " "(free form)"
185 +}
186 +
187 +### set action ###
188 +
189 +describe_set() {
190 + echo "Set the ${EDITOR_VAR} variable in profile"
191 +}
192 +
193 +describe_set_options() {
194 + echo "target : Target name or number (from 'list' action)"
195 +}
196 +
197 +describe_set_parameters() {
198 + echo "<target>"
199 +}
200 +
201 +do_set() {
202 + [[ -z "${1}" ]] && die -q "You didn't tell me what to set the variable to"
203 + [[ ${#@} -gt 1 ]] && die -q "Too many parameters"
204 +
205 + local target="${1}" targets dir ifs_save=${IFS-$' \t\n'}
206 +
207 + # target may be specified by its name or its index
208 + if is_number "${target}"; then
209 + targets=( $(find_targets) )
210 + [[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]] \
211 + || die -q "Number out of range: ${1}"
212 + target=${targets[target-1]}
213 + fi
214 +
215 + # is the target an absolute path? if not, try to find it
216 + if [[ -n ${target##/*} ]]; then
217 + IFS=:
218 + for dir in ${EDITOR_PATH-/bin:/usr/bin}; do
219 + [[ -f "${ROOT}${dir}/${target}" ]] || continue
220 + target=${dir}/${target}
221 + break
222 + done
223 + IFS=${ifs_save}
224 + fi
225 +
226 + # we should now have a path to an existing binary
227 + [[ -z ${target##/*} && -f "${ROOT}${target}" ]] \
228 + || die -q "Target \"${target}\" doesn't appear to be valid!"
229 +
230 + echo "Setting ${EDITOR_VAR} to ${target} ..."
231 + write_env_value "${target}"
232 +
233 + # update profile
234 + do_action env update noldconfig
235 +}
236 +
237 +### update action ###
238 +
239 +describe_update() {
240 + echo "Update the ${EDITOR_VAR} variable if it is unset or invalid"
241 +}
242 +
243 +do_update() {
244 + [[ ${#@} -gt 0 ]] && die -q "Too many parameters"
245 +
246 + local cur targets
247 + cur=$(read_env_value)
248 + [[ -n ${cur} && -f "${ROOT}${cur}" ]] && return
249 +
250 + targets=( $(find_targets) )
251 + [[ ${#targets[@]} -gt 0 ]] \
252 + || die -q "No valid target for ${EDITOR_VAR} found"
253 +
254 + echo "Setting ${EDITOR_VAR} to ${targets[0]} ..."
255 + write_env_value "${targets[0]}"
256 +
257 + do_action env update noldconfig
258 +}
259
260
261 Property changes on: trunk/libs/editor-variable.bash.in
262 ___________________________________________________________________
263 Name: svn:keywords
264 + Author Date Id Revision
265
266 Modified: trunk/modules/Makefile.am
267 ===================================================================
268 --- trunk/modules/Makefile.am 2009-04-19 20:45:58 UTC (rev 471)
269 +++ trunk/modules/Makefile.am 2009-04-20 06:18:33 UTC (rev 472)
270 @@ -3,12 +3,15 @@
271 safe_scripts = \
272 bashcomp.eselect \
273 binutils.eselect \
274 + editor.eselect \
275 env.eselect \
276 kernel.eselect \
277 mailer.eselect \
278 modules.eselect \
279 + pager.eselect \
280 profile.eselect \
281 - rc.eselect
282 + rc.eselect \
283 + visual.eselect
284
285 dodgy_scripts = \
286 config.eselect \
287
288 Added: trunk/modules/editor.eselect
289 ===================================================================
290 --- trunk/modules/editor.eselect (rev 0)
291 +++ trunk/modules/editor.eselect 2009-04-20 06:18:33 UTC (rev 472)
292 @@ -0,0 +1,15 @@
293 +# Copyright 2009 Gentoo Foundation
294 +# Distributed under the terms of the GNU General Public License v2
295 +# $Id$
296 +
297 +EDITOR_VAR="EDITOR"
298 +EDITOR_ENVFILE="/etc/env.d/99editor"
299 +# list of most common cases only
300 +EDITOR_LIST="/bin/nano /usr/bin/emacs /usr/bin/vi /usr/bin/xemacs"
301 +
302 +inherit editor-variable
303 +
304 +DESCRIPTION="Manage ${EDITOR_VAR} variable"
305 +MAINTAINER="ulm@g.o"
306 +SVN_DATE='$Date$'
307 +VERSION=$(svn_date_to_version "${SVN_DATE}")
308
309
310 Property changes on: trunk/modules/editor.eselect
311 ___________________________________________________________________
312 Name: svn:keywords
313 + Author Date Id Revision
314
315 Added: trunk/modules/pager.eselect
316 ===================================================================
317 --- trunk/modules/pager.eselect (rev 0)
318 +++ trunk/modules/pager.eselect 2009-04-20 06:18:33 UTC (rev 472)
319 @@ -0,0 +1,14 @@
320 +# Copyright 2009 Gentoo Foundation
321 +# Distributed under the terms of the GNU General Public License v2
322 +# $Id$
323 +
324 +EDITOR_VAR="PAGER"
325 +EDITOR_ENVFILE="/etc/env.d/99pager"
326 +EDITOR_LIST="/bin/more /usr/bin/less /usr/bin/most"
327 +
328 +inherit editor-variable
329 +
330 +DESCRIPTION="Manage ${EDITOR_VAR} variable"
331 +MAINTAINER="ulm@g.o"
332 +SVN_DATE='$Date$'
333 +VERSION=$(svn_date_to_version "${SVN_DATE}")
334
335
336 Property changes on: trunk/modules/pager.eselect
337 ___________________________________________________________________
338 Name: svn:keywords
339 + Author Date Id Revision
340
341 Added: trunk/modules/visual.eselect
342 ===================================================================
343 --- trunk/modules/visual.eselect (rev 0)
344 +++ trunk/modules/visual.eselect 2009-04-20 06:18:33 UTC (rev 472)
345 @@ -0,0 +1,15 @@
346 +# Copyright 2009 Gentoo Foundation
347 +# Distributed under the terms of the GNU General Public License v2
348 +# $Id$
349 +
350 +EDITOR_VAR="VISUAL"
351 +EDITOR_ENVFILE="/etc/env.d/99editor"
352 +# list of most common cases only
353 +EDITOR_LIST="/bin/nano /usr/bin/emacs /usr/bin/vi /usr/bin/xemacs"
354 +
355 +inherit editor-variable
356 +
357 +DESCRIPTION="Manage ${EDITOR_VAR} variable"
358 +MAINTAINER="ulm@g.o"
359 +SVN_DATE='$Date$'
360 +VERSION=$(svn_date_to_version "${SVN_DATE}")
361
362
363 Property changes on: trunk/modules/visual.eselect
364 ___________________________________________________________________
365 Name: svn:keywords
366 + Author Date Id Revision