summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Müller <ulm@gentoo.org>2019-09-02 12:25:45 +0200
committerUlrich Müller <ulm@gentoo.org>2019-09-02 12:25:45 +0200
commit0905154aae24c2f17b137b45f5a1dd11fb4774fb (patch)
tree98d070daf670e806a1e0827da3e355820d4973d1
parentChangeLog: Use UTF-8. (diff)
downloadeselect-0905154aae24c2f17b137b45f5a1dd11fb4774fb.tar.gz
eselect-0905154aae24c2f17b137b45f5a1dd11fb4774fb.tar.bz2
eselect-0905154aae24c2f17b137b45f5a1dd11fb4774fb.zip
Support relative pathnames in editor-variable library.
* libs/editor-variable.bash.in (find_in_path): New function, looks up its first argument in EDITOR_PATH, and tests if it exists. (find_targets, do_set): Use it. * modules/pager.eselect (EDITOR_LIST): * modules/editor.eselect (EDITOR_LIST): Don't use absolute paths. * man/editor.eselect.5: * man/pager.eselect.5: Update. Signed-off-by: Ulrich Müller <ulm@gentoo.org>
-rw-r--r--ChangeLog10
-rw-r--r--libs/editor-variable.bash.in47
-rw-r--r--man/editor.eselect.514
-rw-r--r--man/pager.eselect.513
-rw-r--r--modules/editor.eselect7
-rw-r--r--modules/pager.eselect2
6 files changed, 56 insertions, 37 deletions
diff --git a/ChangeLog b/ChangeLog
index 94f8577..cbb6229 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2019-09-02 Ulrich Müller <ulm@gentoo.org>
+
+ * libs/editor-variable.bash.in (find_in_path): New function, looks
+ up its first argument in EDITOR_PATH, and tests if it exists.
+ (find_targets, do_set): Use it.
+ * modules/pager.eselect (EDITOR_LIST):
+ * modules/editor.eselect (EDITOR_LIST): Don't use absolute paths.
+ * man/editor.eselect.5:
+ * man/pager.eselect.5: Update.
+
2019-05-26 Ulrich Müller <ulm@gentoo.org>
* modules/news.eselect (do_read, do_unread): Allow specification
diff --git a/libs/editor-variable.bash.in b/libs/editor-variable.bash.in
index ac71ecf..a3bfdc7 100644
--- a/libs/editor-variable.bash.in
+++ b/libs/editor-variable.bash.in
@@ -21,26 +21,49 @@
# 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-separated list of available programs (full pathnames)
-# e.g. "/bin/nano /usr/bin/emacs /usr/bin/vi". Alternatively, items can be of
-# the form "name:/path/to/binary".
+# EDITOR_LIST is a space-separated list of available programs (with or without
+# full pathname), e.g., "nano emacs /usr/bin/vi". Alternatively, items can be
+# of the form "name:/path/to/binary".
# EDITOR_PATH (optional) is a colon-separated list of directories where to
# search for available programs. Default is "/bin:/usr/bin".
inherit config
+# find file in EDITOR_PATH
+find_in_path() {
+ local file=$1
+
+ # do we already have an absolute path?
+ if [[ ${file} == /* ]]; then
+ [[ -f ${ROOT}${file} ]]
+ return
+ fi
+
+ # try to find it
+ local IFS=:
+ for dir in ${EDITOR_PATH-/bin:/usr/bin}; do
+ [[ -f ${EROOT}${dir}/${file} ]] && return 0
+ done
+ return 1
+}
+
# find a list of valid targets
find_targets() {
- local cur i
+ local cur i file
for i in ${EDITOR_LIST}; do
- [[ -f ${EROOT}${i#*:} ]] && echo "${EPREFIX}${i%%:*}"
+ file=${i#*:}
+ [[ ${file} == /* ]] && file=${EPREFIX}${file}
+ if find_in_path "${file}"; then
+ [[ ${i} == *:* ]] && echo "${i%%:*}" || echo "${file}"
+ fi
done
# also output the current value if it isn't in our list
cur=$(read_env_value)
- [[ -n ${cur} && ${EDITOR_LIST} != *:* && -f ${ROOT}${cur} ]] \
+ [[ -n ${cur} && ${EDITOR_LIST} != *:* ]] \
&& ! has "${cur#${EPREFIX}}" ${EDITOR_LIST} \
+ && find_in_path "${cur}" \
&& echo "${cur}"
}
@@ -130,18 +153,8 @@ do_set() {
fi
if [[ ${EDITOR_LIST} != *:* ]]; then
- # is the target an absolute path? if not, try to find it
- if [[ ${target} != /* ]]; then
- local ifs_save=${IFS} IFS=:
- for dir in ${EDITOR_PATH-/bin:/usr/bin}; do
- [[ -f ${EROOT}${dir}/${target} ]] || continue
- target=${EPREFIX}${dir}/${target}
- break
- done
- IFS=${ifs_save}
- fi
# target is valid if it's a path to an existing binary
- [[ ${target} == /* && -f ${ROOT}${target} ]] \
+ find_in_path "${target}" \
|| die -q "Target \"${target}\" doesn't appear to be valid!"
else
# target is valid only if it's in our list
diff --git a/man/editor.eselect.5 b/man/editor.eselect.5
index 218500a..8a296f1 100644
--- a/man/editor.eselect.5
+++ b/man/editor.eselect.5
@@ -2,7 +2,7 @@
.\" Copyright 2009-2019 Gentoo Authors
.\" Distributed under the terms of the GNU GPL version 2 or later
.\"
-.TH editor.eselect 5 "September 2012" "Gentoo Linux" eselect
+.TH editor.eselect 5 "September 2019" "Gentoo Linux" eselect
.SH NAME
editor.eselect \- The EDITOR management module for Gentoo's eselect
.SH SYNOPSIS
@@ -32,9 +32,9 @@ variable.
.br
Available targets for the EDITOR variable:
.br
- [1] /bin/nano *
- [2] /usr/bin/emacs
- [3] /usr/bin/vi
+ [1] nano *
+ [2] emacs
+ [3] vi
[ ] (free form)
.SH ACTION: SET
.B eselect editor set
@@ -46,11 +46,11 @@ variable in the system profile.
.I target
can be either an identification number given by
.B eselect editor list
-or the name of an installed text editor.
+or the name (with or without full path) of an installed text editor.
# eselect editor set emacs
.br
-Setting EDITOR to /usr/bin/emacs ...
+Setting EDITOR to emacs ...
.br
Run ". /etc/profile" to update the variable in your shell.
.SH ACTION: SHOW
@@ -64,7 +64,7 @@ variable in the system profile.
.br
EDITOR variable in profile:
.br
- /usr/bin/emacs
+ emacs
.SH ACTION: UPDATE
.B eselect editor update
.br
diff --git a/man/pager.eselect.5 b/man/pager.eselect.5
index a0d1052..e5ac4c6 100644
--- a/man/pager.eselect.5
+++ b/man/pager.eselect.5
@@ -2,7 +2,7 @@
.\" Copyright 2009-2019 Gentoo Authors
.\" Distributed under the terms of the GNU GPL version 2 or later
.\"
-.TH pager.eselect 5 "June 2016" "Gentoo Linux" eselect
+.TH pager.eselect 5 "September 2019" "Gentoo Linux" eselect
.SH NAME
pager.eselect \- The PAGER management module for Gentoo's eselect
.SH SYNOPSIS
@@ -32,8 +32,8 @@ variable.
.br
Available targets for the PAGER variable:
.br
- [1] /usr/bin/less
- [2] /bin/more *
+ [1] less
+ [2] more *
[ ] (free form)
.SH ACTION: SET
.B eselect pager set
@@ -45,11 +45,12 @@ variable in the system profile.
.I target
can be either an identification number given by
.B eselect pager list
-or the name of an installed terminal pager program.
+or the name (with or without full path) of an installed terminal pager
+program.
# eselect pager set 2
.br
-Setting PAGER to /usr/bin/less ...
+Setting PAGER to less ...
.br
Run ". /etc/profile" to update the variable in your shell.
.SH ACTION: SHOW
@@ -63,7 +64,7 @@ variable in the system profile.
.br
PAGER variable in profile:
.br
- /usr/bin/less
+ less
.SH ACTION: UPDATE
.B eselect pager update
.br
diff --git a/modules/editor.eselect b/modules/editor.eselect
index 1bee5ac..835b9e8 100644
--- a/modules/editor.eselect
+++ b/modules/editor.eselect
@@ -5,12 +5,7 @@
EDITOR_VAR="EDITOR"
EDITOR_ENVFILE="/etc/env.d/99editor"
# list of most common cases only
-EDITOR_LIST="/bin/nano
- /bin/ed
- /usr/bin/emacs
- /usr/bin/ex
- /usr/bin/vi
- /usr/bin/xemacs"
+EDITOR_LIST="nano ed emacs ex vi xemacs"
inherit editor-variable
diff --git a/modules/pager.eselect b/modules/pager.eselect
index d0ff910..8c5d7fd 100644
--- a/modules/pager.eselect
+++ b/modules/pager.eselect
@@ -4,7 +4,7 @@
EDITOR_VAR="PAGER"
EDITOR_ENVFILE="/etc/env.d/99pager"
-EDITOR_LIST="/usr/bin/less /bin/more /usr/bin/most"
+EDITOR_LIST="less more most"
inherit editor-variable