* [gentoo-commits] eselect r472 - in trunk: . libs modules
@ 2009-04-20 6:18 Ulrich Mueller (ulm)
0 siblings, 0 replies; only message in thread
From: Ulrich Mueller (ulm) @ 2009-04-20 6:18 UTC (permalink / raw
To: gentoo-commits
Author: ulm
Date: 2009-04-20 06:18:33 +0000 (Mon, 20 Apr 2009)
New Revision: 472
Added:
trunk/libs/editor-variable.bash.in
trunk/modules/editor.eselect
trunk/modules/pager.eselect
trunk/modules/visual.eselect
Modified:
trunk/AUTHORS
trunk/ChangeLog
trunk/NEWS
trunk/libs/Makefile.am
trunk/modules/Makefile.am
Log:
New modules for the EDITOR, VISUAL, and PAGER environment variables.
Modified: trunk/AUTHORS
===================================================================
--- trunk/AUTHORS 2009-04-19 20:45:58 UTC (rev 471)
+++ trunk/AUTHORS 2009-04-20 06:18:33 UTC (rev 472)
@@ -34,4 +34,5 @@
Modules: emacs
Ulrich Mueller <ulm@gentoo.org>
- Modules: ctags, emacs
+ Modules: ctags, editor, emacs, pager, visual
+ Libraries: editor-variable
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-04-19 20:45:58 UTC (rev 471)
+++ trunk/ChangeLog 2009-04-20 06:18:33 UTC (rev 472)
@@ -1,3 +1,14 @@
+2009-04-20 Ulrich Mueller <ulm@gentoo.org>
+
+ * libs/editor-variable.bash.in:
+ * modules/editor.eselect:
+ * modules/visual.eselect:
+ * modules/pager.eselect: New modules and library, managing the
+ EDITOR, VISUAL and PAGER environment variables; bug 190216.
+ * libs/Makefile.am (eselectlibs_SCRIPTS, EXTRA_DIST):
+ * modules/Makefile.am (safe_scripts): Add the new files.
+ * NEWS: Mention the new feature.
+
2009-04-18 Ulrich Mueller <ulm@gentoo.org>
* modules/rc.eselect (do_delete): Don't die if the script is no
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2009-04-19 20:45:58 UTC (rev 471)
+++ trunk/NEWS 2009-04-20 06:18:33 UTC (rev 472)
@@ -11,6 +11,7 @@
- Add a new module, for listing and querying eselect modules.
- Allow setting system-wide default dictionary.
- Treat 'help' and 'version' options as if they were actions.
+ - Modules for the EDITOR, VISUAL, and PAGER environment variables.
1.0.12:
Bug fixes:
Modified: trunk/libs/Makefile.am
===================================================================
--- trunk/libs/Makefile.am 2009-04-19 20:45:58 UTC (rev 471)
+++ trunk/libs/Makefile.am 2009-04-20 06:18:33 UTC (rev 472)
@@ -4,6 +4,7 @@
config.bash \
core.bash \
default.eselect \
+ editor-variable.eselect \
manip.bash \
multilib.bash \
output.bash \
@@ -18,6 +19,7 @@
config.bash.in \
core.bash.in \
default.eselect.in \
+ editor-variable.eselect.in \
manip.bash.in \
multilib.bash.in \
output.bash.in \
Added: trunk/libs/editor-variable.bash.in
===================================================================
--- trunk/libs/editor-variable.bash.in (rev 0)
+++ trunk/libs/editor-variable.bash.in 2009-04-20 06:18:33 UTC (rev 472)
@@ -0,0 +1,169 @@
+#!/bin/bash
+
+# Copyright (c) 2009 Gentoo Foundation
+# $Id$
+# This file is part of the 'eselect' tools framework.
+#
+# eselect is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 2 of the License, or (at your option) any later
+# version.
+#
+# eselect is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# eselect. If not, see <http://www.gnu.org/licenses/>.
+
+# This library is for managing environment variables like EDITOR or PAGER.
+# To use it, you must set the following variables:
+#
+# EDITOR_VAR is the name of the environment variable, e.g. "EDITOR".
+# EDITOR_ENVFILE is the path to the config file where the variable should be
+# stored, e.g. "/etc/env.d/99editor". Several modules may share the same file.
+# EDITOR_LIST is a space-seperated list of available programs (full pathnames)
+# e.g. "/bin/nano /usr/bin/emacs /usr/bin/vi"
+# EDITOR_PATH (optional) is a colon-separated list of directories where to
+# search for available programs. Default is "/bin:/usr/bin".
+
+inherit config
+
+# find a list of valid targets
+find_targets() {
+ local cur targets i
+ targets=${EDITOR_LIST}
+ cur=$(read_env_value)
+
+ # also include the current value if it's not already in our list
+ [[ -n ${cur} ]] && ! has "${cur}" "${targets}" \
+ && targets="${targets} ${cur}"
+
+ for i in ${targets}; do
+ [[ -f "${ROOT}${i}" ]] && echo "${i}"
+ done
+}
+
+# read variable value from config file
+read_env_value() {
+ load_config "${ROOT}${EDITOR_ENVFILE}" "${EDITOR_VAR}"
+}
+
+# write variable to config file
+write_env_value() {
+ [[ -w "${ROOT}${EDITOR_ENVFILE%/*}" ]] \
+ || die -q "You need root privileges!"
+ store_config "${ROOT}${EDITOR_ENVFILE}" "${EDITOR_VAR}" "${1}"
+}
+
+### show action ###
+
+describe_show() {
+ echo "Show value of the ${EDITOR_VAR} variable in profile"
+}
+
+do_show() {
+ [[ ${#@} -gt 0 ]] && die -q "Too many parameters"
+
+ local cur=$(read_env_value)
+ write_list_start "${EDITOR_VAR} variable in profile:"
+ write_kv_list_entry "${cur:-(none)}"
+}
+
+### list action ###
+
+describe_list() {
+ echo "List available targets for the ${EDITOR_VAR} variable"
+}
+
+do_list() {
+ [[ ${#@} -gt 0 ]] && die -q "Too many parameters"
+
+ local cur targets i
+ cur=$(read_env_value)
+ targets=( $(find_targets) )
+
+ write_list_start "Available targets for the ${EDITOR_VAR} variable:"
+ if [[ -n ${targets[@]} ]]; then
+ for (( i = 0; i < ${#targets[@]}; i = i + 1 )); do
+ # Display a star to indicate the currently chosen version
+ [[ ${targets[i]} = ${cur} ]] \
+ && targets[i]="${targets[i]} $(highlight '*')"
+ done
+ write_numbered_list "${targets[@]}"
+ fi
+ write_numbered_list_entry " " "(free form)"
+}
+
+### set action ###
+
+describe_set() {
+ echo "Set the ${EDITOR_VAR} variable in profile"
+}
+
+describe_set_options() {
+ echo "target : Target name or number (from 'list' action)"
+}
+
+describe_set_parameters() {
+ echo "<target>"
+}
+
+do_set() {
+ [[ -z "${1}" ]] && die -q "You didn't tell me what to set the variable to"
+ [[ ${#@} -gt 1 ]] && die -q "Too many parameters"
+
+ local target="${1}" targets dir ifs_save=${IFS-$' \t\n'}
+
+ # target may be specified by its name or its index
+ if is_number "${target}"; then
+ targets=( $(find_targets) )
+ [[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]] \
+ || die -q "Number out of range: ${1}"
+ target=${targets[target-1]}
+ fi
+
+ # is the target an absolute path? if not, try to find it
+ if [[ -n ${target##/*} ]]; then
+ IFS=:
+ for dir in ${EDITOR_PATH-/bin:/usr/bin}; do
+ [[ -f "${ROOT}${dir}/${target}" ]] || continue
+ target=${dir}/${target}
+ break
+ done
+ IFS=${ifs_save}
+ fi
+
+ # we should now have a path to an existing binary
+ [[ -z ${target##/*} && -f "${ROOT}${target}" ]] \
+ || die -q "Target \"${target}\" doesn't appear to be valid!"
+
+ echo "Setting ${EDITOR_VAR} to ${target} ..."
+ write_env_value "${target}"
+
+ # update profile
+ do_action env update noldconfig
+}
+
+### update action ###
+
+describe_update() {
+ echo "Update the ${EDITOR_VAR} variable if it is unset or invalid"
+}
+
+do_update() {
+ [[ ${#@} -gt 0 ]] && die -q "Too many parameters"
+
+ local cur targets
+ cur=$(read_env_value)
+ [[ -n ${cur} && -f "${ROOT}${cur}" ]] && return
+
+ targets=( $(find_targets) )
+ [[ ${#targets[@]} -gt 0 ]] \
+ || die -q "No valid target for ${EDITOR_VAR} found"
+
+ echo "Setting ${EDITOR_VAR} to ${targets[0]} ..."
+ write_env_value "${targets[0]}"
+
+ do_action env update noldconfig
+}
Property changes on: trunk/libs/editor-variable.bash.in
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Modified: trunk/modules/Makefile.am
===================================================================
--- trunk/modules/Makefile.am 2009-04-19 20:45:58 UTC (rev 471)
+++ trunk/modules/Makefile.am 2009-04-20 06:18:33 UTC (rev 472)
@@ -3,12 +3,15 @@
safe_scripts = \
bashcomp.eselect \
binutils.eselect \
+ editor.eselect \
env.eselect \
kernel.eselect \
mailer.eselect \
modules.eselect \
+ pager.eselect \
profile.eselect \
- rc.eselect
+ rc.eselect \
+ visual.eselect
dodgy_scripts = \
config.eselect \
Added: trunk/modules/editor.eselect
===================================================================
--- trunk/modules/editor.eselect (rev 0)
+++ trunk/modules/editor.eselect 2009-04-20 06:18:33 UTC (rev 472)
@@ -0,0 +1,15 @@
+# Copyright 2009 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+EDITOR_VAR="EDITOR"
+EDITOR_ENVFILE="/etc/env.d/99editor"
+# list of most common cases only
+EDITOR_LIST="/bin/nano /usr/bin/emacs /usr/bin/vi /usr/bin/xemacs"
+
+inherit editor-variable
+
+DESCRIPTION="Manage ${EDITOR_VAR} variable"
+MAINTAINER="ulm@gentoo.org"
+SVN_DATE='$Date$'
+VERSION=$(svn_date_to_version "${SVN_DATE}")
Property changes on: trunk/modules/editor.eselect
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Added: trunk/modules/pager.eselect
===================================================================
--- trunk/modules/pager.eselect (rev 0)
+++ trunk/modules/pager.eselect 2009-04-20 06:18:33 UTC (rev 472)
@@ -0,0 +1,14 @@
+# Copyright 2009 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+EDITOR_VAR="PAGER"
+EDITOR_ENVFILE="/etc/env.d/99pager"
+EDITOR_LIST="/bin/more /usr/bin/less /usr/bin/most"
+
+inherit editor-variable
+
+DESCRIPTION="Manage ${EDITOR_VAR} variable"
+MAINTAINER="ulm@gentoo.org"
+SVN_DATE='$Date$'
+VERSION=$(svn_date_to_version "${SVN_DATE}")
Property changes on: trunk/modules/pager.eselect
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Added: trunk/modules/visual.eselect
===================================================================
--- trunk/modules/visual.eselect (rev 0)
+++ trunk/modules/visual.eselect 2009-04-20 06:18:33 UTC (rev 472)
@@ -0,0 +1,15 @@
+# Copyright 2009 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+EDITOR_VAR="VISUAL"
+EDITOR_ENVFILE="/etc/env.d/99editor"
+# list of most common cases only
+EDITOR_LIST="/bin/nano /usr/bin/emacs /usr/bin/vi /usr/bin/xemacs"
+
+inherit editor-variable
+
+DESCRIPTION="Manage ${EDITOR_VAR} variable"
+MAINTAINER="ulm@gentoo.org"
+SVN_DATE='$Date$'
+VERSION=$(svn_date_to_version "${SVN_DATE}")
Property changes on: trunk/modules/visual.eselect
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-04-20 6:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-20 6:18 [gentoo-commits] eselect r472 - in trunk: . libs modules Ulrich Mueller (ulm)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox