aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Müller <ulm@gentoo.org>2009-05-19 06:26:20 +0000
committerUlrich Müller <ulm@gentoo.org>2009-05-19 06:26:20 +0000
commitcf9c7213430d7f22341c44a555fce3ca2790992b (patch)
tree77137c9eadb2cd963accf03cfa07add3a0bb945f
parentUpdate version to 1.1_rc1. (diff)
downloadeselect-cf9c7213430d7f22341c44a555fce3ca2790992b.tar.gz
eselect-cf9c7213430d7f22341c44a555fce3ca2790992b.tar.bz2
eselect-cf9c7213430d7f22341c44a555fce3ca2790992b.zip
Use consistent indentation for all source files.
svn path=/trunk/; revision=546
-rw-r--r--ChangeLog4
-rw-r--r--README5
-rwxr-xr-xbin/eselect.in140
-rw-r--r--libs/config.bash.in168
-rw-r--r--libs/core.bash.in150
-rw-r--r--libs/default.eselect.in138
-rw-r--r--libs/editor-variable.bash.in172
-rw-r--r--libs/manip.bash.in20
-rw-r--r--libs/multilib.bash.in36
-rw-r--r--libs/output.bash.in292
-rw-r--r--libs/package-manager.bash.in176
-rw-r--r--libs/path-manipulation.bash.in16
-rw-r--r--libs/skel.bash.in454
-rw-r--r--libs/tests.bash.in26
-rw-r--r--modules/config.eselect1
-rw-r--r--modules/esd.eselect1
-rw-r--r--modules/timidity.eselect3
-rw-r--r--modules/vi.eselect1
18 files changed, 873 insertions, 930 deletions
diff --git a/ChangeLog b/ChangeLog
index 2b2253a..c2ed00d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-05-19 Ulrich Mueller <ulm@gentoo.org>
+
+ * README: Use consistent indentation for all source files.
+
2009-05-18 Ulrich Mueller <ulm@gentoo.org>
* configure.ac: Update version to 1.1_rc1.
diff --git a/README b/README
index 431fe18..da018b3 100644
--- a/README
+++ b/README
@@ -22,8 +22,9 @@ Style Notes
* Always use ``[[ brackets ]]``, never `[ brackets ]`.
* Use quotes on variables where necessary.
-* For the main source, indent is four spaces, no tabs, text width of 80.
-* For .eselect files, the same indenting rules apply as for ebuilds.
+* For all source files, the same indenting rules apply as for ebuilds:
+ one tab per indent level, with each tab representing 4 places.
+* Avoid lines wider than 79 positions.
* Public functions don't get the ``ec_`` prefix, private functions do.
* eval is evil, so we disabled it.
* Absolute paths to executables are not portable, so don't use them.
diff --git a/bin/eselect.in b/bin/eselect.in
index 8973e89..ffe6966 100755
--- a/bin/eselect.in
+++ b/bin/eselect.in
@@ -1,6 +1,5 @@
#!/bin/bash
-
-# Copyright (c) 2005-2009 Gentoo Foundation.
+# Copyright (c) 2005-2009 Gentoo Foundation -*-eselect-*-
# $Id$
# This file is part of the 'eselect' tools framework.
#
@@ -24,8 +23,8 @@ ESELECT_DEFAULT_MODULES_PATH="${ESELECT_DATA_PATH}/modules"
# Look in these places for modules
ESELECT_MODULES_PATH=( \
- "${HOME}/.eselect/modules" \
- "${ESELECT_DEFAULT_MODULES_PATH}" )
+ "${HOME}/.eselect/modules" \
+ "${ESELECT_DEFAULT_MODULES_PATH}" )
# Look in this place for libraries
ESELECT_CORE_PATH="${ESELECT_DATA_PATH}/libs"
@@ -68,63 +67,63 @@ trap 'echo "exiting" >&2; exit 250' 15
# Find and echo the filename of the foo module. If there's no foo module,
# die.
ec_find_module() {
- local modname="$1" modpath="" modfile=""
- [[ -z ${modname} ]] && die "Usage: ${FUNCNAME} <module>"
- for modpath in "${ESELECT_MODULES_PATH[@]}" ; do
- [[ -f ${modpath}/${modname}.eselect ]] && break
- done
-
- modfile="${modpath}/${modname}.eselect"
- [[ -r ${modfile} ]] || die -q "Can't load module ${modname}"
- echo ${modfile}
+ local modname="$1" modpath="" modfile=""
+ [[ -z ${modname} ]] && die "Usage: ${FUNCNAME} <module>"
+ for modpath in "${ESELECT_MODULES_PATH[@]}" ; do
+ [[ -f ${modpath}/${modname}.eselect ]] && break
+ done
+
+ modfile="${modpath}/${modname}.eselect"
+ [[ -r ${modfile} ]] || die -q "Can't load module ${modname}"
+ echo ${modfile}
}
# ec_do_usage
# Display eselect usage
ec_do_usage() {
- echo "Usage: eselect <global options> <module name> <module options>"
+ echo "Usage: eselect <global options> <module name> <module options>"
}
# ec_do_help
# Display eselect help
ec_do_help() {
- ec_do_usage
- echo
- ec_do_list-options
- echo
- ec_do_list-modules
+ ec_do_usage
+ echo
+ ec_do_list-options
+ echo
+ ec_do_list-modules
}
# ec_do_version
# Display eselect version
ec_do_version() {
- echo "eselect ${ESELECT_VERSION}"
- echo
- echo "Copyright (c) 2005-2009 Gentoo Foundation."
- echo "Distributed under the terms of the GNU General Public License v2."
+ echo "eselect ${ESELECT_VERSION}"
+ echo
+ echo "Copyright (c) 2005-2009 Gentoo Foundation."
+ echo "Distributed under the terms of the GNU General Public License v2."
}
# ec_do_list-options
# Display all recognized global options
ec_do_list-options() {
- write_list_start "Global options:"
- write_kv_list_entry "--no-color,--no-colour" "Disable coloured output"
+ write_list_start "Global options:"
+ write_kv_list_entry "--no-color,--no-colour" "Disable coloured output"
}
# ec_do_list-modules
# Display all available eselect modules DEPRECATED
ec_do_list-modules() {
- do_action modules list "$@"
+ do_action modules list "$@"
}
### main code ###
# enable colour output and get width of terminal iff stdout is a tty
if [[ -t 1 ]]; then
- colours
- init_columns
+ colours
+ init_columns
else
- nocolours
+ nocolours
fi
# figure out what the action is. we need to know whether we're
@@ -132,60 +131,55 @@ fi
action=""
for suffix in config update{,r} tool manager reader ; do
- if [[ ${0%%-${suffix}} != ${0} ]] ; then
- action=$(basename "${0}" )
- action=${action%%-${suffix}}
- break
- fi
+ if [[ ${0%%-${suffix}} != ${0} ]] ; then
+ action=$(basename "${0}" )
+ action=${action%%-${suffix}}
+ break
+ fi
done
unset suffix
if [[ -z ${action} ]] ; then
- binname=$(basename "${0}" )
- for prefix in config update{,r} manage 'read' ; do
- if [[ ${binname##${prefix}-} != ${binname} ]] ; then
- action=$(basename "${0}" )
- action=${action##${prefix}-}
- break
- fi
- done
- unset binname prefix
+ binname=$(basename "${0}" )
+ for prefix in config update{,r} manage 'read' ; do
+ if [[ ${binname##${prefix}-} != ${binname} ]] ; then
+ action=$(basename "${0}" )
+ action=${action##${prefix}-}
+ break
+ fi
+ done
+ unset binname prefix
fi
if [[ -z ${action} ]] && [[ -n ${1##--} ]] ; then
- while [[ ${1##--} != ${1} ]] ; do
- has ${1##--} ${ESELECT_KNOWN_OPTIONS} || \
- die -q "Unknown option ${1}!"
- case ${1##--} in
- no-colour|no-color)
- ESELECT_OPTIONS="${ESELECT_OPTIONS} NOCOLOUR"
- nocolours
- ;;
- help|version)
- action=${1##--}
- ;;
- esac
- shift
- done
- if [[ -z ${action} ]]; then
- action=${1}
- shift
- fi
+ while [[ ${1##--} != ${1} ]] ; do
+ has ${1##--} ${ESELECT_KNOWN_OPTIONS} || \
+ die -q "Unknown option ${1}!"
+ case ${1##--} in
+ no-colour|no-color)
+ ESELECT_OPTIONS="${ESELECT_OPTIONS} NOCOLOUR"
+ nocolours
+ ;;
+ help|version)
+ action=${1##--}
+ ;;
+ esac
+ shift
+ done
+ if [[ -z ${action} ]]; then
+ action=${1}
+ shift
+ fi
fi
if [[ -n ${action} ]] ; then
- if is_function "ec_do_${action}" ; then
- ec_do_${action} "$@"
- else
- do_action "${action}" "$@"
- fi
+ if is_function "ec_do_${action}" ; then
+ ec_do_${action} "$@"
+ else
+ do_action "${action}" "$@"
+ fi
else
- ec_do_help
+ ec_do_help
fi
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
-
-# vim: set sw=4 et sts=4 tw=80 :
+# vim: set ft=eselect :
diff --git a/libs/config.bash.in b/libs/config.bash.in
index 200a9f5..fc7e1cf 100644
--- a/libs/config.bash.in
+++ b/libs/config.bash.in
@@ -1,6 +1,5 @@
#!/bin/bash
-
-# Copyright (c) 2005-2009 Gentoo Foundation.
+# Copyright (c) 2005-2009 Gentoo Foundation -*-eselect-*-
# $Id$
# This file is part of the 'eselect' tools framework.
#
@@ -19,110 +18,105 @@
# store_config file key value PUBLIC
# Stores a $key/$value pair for given module in $configfile
store_config() {
- # we need at least "module" and "key"
- [[ ${#@} -ge 2 ]] || die
- local configfile=${1} key=${2} value content vars line="" changed=0
- shift 2
- value=${@}
+ # we need at least "module" and "key"
+ [[ ${#@} -ge 2 ]] || die
+ local configfile=${1} key=${2} value content vars line="" changed=0
+ shift 2
+ value=${@}
- if [[ ! -e ${configfile} ]] ; then
- mkdir -p ${configfile%/*} \
- || die -q \
- "Couldn't create directory ${configfile%/*}"
- fi
+ if [[ ! -e ${configfile} ]] ; then
+ mkdir -p ${configfile%/*} \
+ || die -q \
+ "Couldn't create directory ${configfile%/*}"
+ fi
- store_config_header() {
- echo "# Configuration file for eselect" \
- > ${configfile}
- echo "# This file has been automatically generated." \
- >> ${configfile}
- }
+ store_config_header() {
+ echo "# Configuration file for eselect" \
+ > ${configfile}
+ echo "# This file has been automatically generated." \
+ >> ${configfile}
+ }
- if [[ ! -f ${configfile} ]] ; then
- store_config_header
- echo "${key}=\"${value}\"" \
- >> ${configfile}
- return
- fi
+ if [[ ! -f ${configfile} ]] ; then
+ store_config_header
+ echo "${key}=\"${value}\"" \
+ >> ${configfile}
+ return
+ fi
- content=$(<${configfile})
+ content=$(<${configfile})
- if [[ -z ${content} ]] ; then
- store_config_header
- echo "${key}=\"${value}\"" \
- >> ${configfile}
- return
- fi
+ if [[ -z ${content} ]] ; then
+ store_config_header
+ echo "${key}=\"${value}\"" \
+ >> ${configfile}
+ return
+ fi
- (
- # parse the names of all settings in the file
- local ifs_save=${IFS-$' \t\n'}
- IFS=$'\n'
- for line in ${content} ; do
- [[ ${line/=/} != ${line} ]] || continue
- line=${line/=*/}
- local ${line}=""
- vars=(${vars[@]} ${line})
- done
- IFS=${ifs_save}
+ (
+ # parse the names of all settings in the file
+ local ifs_save=${IFS-$' \t\n'}
+ IFS=$'\n'
+ for line in ${content} ; do
+ [[ ${line/=/} != ${line} ]] || continue
+ line=${line/=*/}
+ local ${line}=""
+ vars=(${vars[@]} ${line})
+ done
+ IFS=${ifs_save}
- source ${configfile} 2>&1 > /dev/null \
- || die "Failed to source ${configfile}."
+ source ${configfile} 2>&1 > /dev/null \
+ || die "Failed to source ${configfile}."
- store_config_header
- for var in ${vars[@]} ; do
- if [[ ${var} == ${key} ]] ; then
- echo "${var}=\"${value}\"" \
- >> ${configfile}
- changed=1
- else
- echo "${var}=\"${!var}\"" \
- >> ${configfile}
- fi
- done
- [[ ${changed} == 1 ]] \
- || echo "${key}=\"${value}\"" \
- >> ${configfile}
- )
+ store_config_header
+ for var in ${vars[@]} ; do
+ if [[ ${var} == ${key} ]] ; then
+ echo "${var}=\"${value}\"" \
+ >> ${configfile}
+ changed=1
+ else
+ echo "${var}=\"${!var}\"" \
+ >> ${configfile}
+ fi
+ done
+ [[ ${changed} == 1 ]] \
+ || echo "${key}=\"${value}\"" \
+ >> ${configfile}
+ )
}
# load_config module key PUBLIC
# Loads $key value from $configfile
load_config() {
- [[ ${#@} -eq 2 ]] || die
- local configfile key value
+ [[ ${#@} -eq 2 ]] || die
+ local configfile key value
- configfile=${1}
- key=${2}
- [[ ! -e ${configfile} ]] \
- && return 1
- value=$(
- unset ${key}
- source ${configfile} 1>&2 > /dev/null \
- || die "Failed to source ${configfile}."
- echo "${!key}"
- )
- echo "${value}"
+ configfile=${1}
+ key=${2}
+ [[ ! -e ${configfile} ]] \
+ && return 1
+ value=$(
+ unset ${key}
+ source ${configfile} 1>&2 > /dev/null \
+ || die "Failed to source ${configfile}."
+ echo "${!key}"
+ )
+ echo "${value}"
}
# append_config file key item ... PUBLIC
# Appends $item to already stored value of $key in $configfile
# if $item is not already part of $key
append_config() {
- [[ ${#@} -gt 2 ]] || die
- local configfile=${1} key=${2} item oldvalue newvalue
- shift 2
- item="$@"
- oldvalue=$(load_config ${configfile} ${key})
- if ! has ${item} ${oldvalue[@]} ; then
- newvalue=( ${oldvalue[@]} ${item} )
- store_config ${configfile} ${key} ${newvalue[@]}
- fi
+ [[ ${#@} -gt 2 ]] || die
+ local configfile=${1} key=${2} item oldvalue newvalue
+ shift 2
+ item="$@"
+ oldvalue=$(load_config ${configfile} ${key})
+ if ! has ${item} ${oldvalue[@]} ; then
+ newvalue=( ${oldvalue[@]} ${item} )
+ store_config ${configfile} ${key} ${newvalue[@]}
+ fi
}
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
-
-# vim: set sw=4 et sts=4 tw=80 :
+# vim: set ft=eselect :
diff --git a/libs/core.bash.in b/libs/core.bash.in
index ed35695..d0ee46a 100644
--- a/libs/core.bash.in
+++ b/libs/core.bash.in
@@ -1,6 +1,5 @@
#!/bin/bash
-
-# Copyright (c) 2005-2009 Gentoo Foundation.
+# Copyright (c) 2005-2009 Gentoo Foundation -*-eselect-*-
# $Id$
# This file is part of the 'eselect' tools framework.
#
@@ -19,104 +18,99 @@
# check_do function args
# Check that function exists, and call it with args.
check_do() {
- local function="${1}"
- shift
- if is_function "${function}" ; then
- ${function} "$@"
- else
- die "No function ${function}"
- fi
+ local function="${1}"
+ shift
+ if is_function "${function}" ; then
+ ${function} "$@"
+ else
+ die "No function ${function}"
+ fi
}
# die [-q] "Message" PUBLIC
# Display "Message" as an error. If -q is not provided, gives a stacktrace.
die() {
- local item funcname="" sourcefile="" lineno="" n e s="yes"
-
- # do we have a working write_error_msg?
- if is_function "write_error_msg" ; then
- e="write_error_msg"
- else
- e="echo"
- fi
-
- # quiet?
- if [[ ${1} == "-q" ]] ; then
- s=""
- shift
- fi
-
- $e "${@:-(no message)}"
-
- if [[ -n "${s}" ]] ; then
- echo "Call stack:" 1>&2
- for (( n = 1 ; n < ${#FUNCNAME[@]} ; ++n )) ; do
- funcname=${FUNCNAME[${n}]}
- sourcefile=$(basename ${BASH_SOURCE[${n}]})
- lineno=${BASH_LINENO[$(( n - 1 ))]}
- echo " * ${funcname} (${sourcefile}:${lineno})" 1>&2
- done
- fi
-
- # Evil, but effective.
- kill ${ESELECT_KILL_TARGET}
- exit 249
+ local item funcname="" sourcefile="" lineno="" n e s="yes"
+
+ # do we have a working write_error_msg?
+ if is_function "write_error_msg" ; then
+ e="write_error_msg"
+ else
+ e="echo"
+ fi
+
+ # quiet?
+ if [[ ${1} == "-q" ]] ; then
+ s=""
+ shift
+ fi
+
+ $e "${@:-(no message)}"
+
+ if [[ -n "${s}" ]] ; then
+ echo "Call stack:" 1>&2
+ for (( n = 1 ; n < ${#FUNCNAME[@]} ; ++n )) ; do
+ funcname=${FUNCNAME[${n}]}
+ sourcefile=$(basename ${BASH_SOURCE[${n}]})
+ lineno=${BASH_LINENO[$(( n - 1 ))]}
+ echo " * ${funcname} (${sourcefile}:${lineno})" 1>&2
+ done
+ fi
+
+ # Evil, but effective.
+ kill ${ESELECT_KILL_TARGET}
+ exit 249
}
# do_action action args...
# Load and do 'action' with the specified args
do_action() {
- local action="${1##--}" modfile="" subaction="${2##--}"
- [[ -z ${action} ]] && die "Usage: do_action <action> <args>"
- shift; shift
-
- ESELECT_MODULE_NAME="${action}"
- ESELECT_COMMAND="${ESELECT_PROGRAM_NAME} ${ESELECT_MODULE_NAME}"
-
- [[ ${ESELECT_BINARY_NAME##*/} != ${ESELECT_PROGRAM_NAME} ]] && \
- ESELECT_COMMAND="${ESELECT_BINARY_NAME##*/}"
-
- modfile=$( ec_find_module "${action}" )
- (
- source "$ESELECT_DEFAULT_ACTIONS" 2>/dev/null \
- || die "Couldn't source ${ESELECT_DEFAULT_ACTIONS}"
- source "${modfile}" 2>/dev/null \
- || die "Couldn't source ${modfile}"
- if [[ -z ${subaction} ]] ; then
- check_do "do_${DEFAULT_ACTION:-usage}" "$@"
- else
- is_function "do_${subaction}" \
- || die -q "Action ${subaction} unknown"
- check_do "do_${subaction}" "$@"
- fi
- )
+ local action="${1##--}" modfile="" subaction="${2##--}"
+ [[ -z ${action} ]] && die "Usage: do_action <action> <args>"
+ shift; shift
+
+ ESELECT_MODULE_NAME="${action}"
+ ESELECT_COMMAND="${ESELECT_PROGRAM_NAME} ${ESELECT_MODULE_NAME}"
+
+ [[ ${ESELECT_BINARY_NAME##*/} != ${ESELECT_PROGRAM_NAME} ]] && \
+ ESELECT_COMMAND="${ESELECT_BINARY_NAME##*/}"
+
+ modfile=$( ec_find_module "${action}" )
+ (
+ source "$ESELECT_DEFAULT_ACTIONS" 2>/dev/null \
+ || die "Couldn't source ${ESELECT_DEFAULT_ACTIONS}"
+ source "${modfile}" 2>/dev/null \
+ || die "Couldn't source ${modfile}"
+ if [[ -z ${subaction} ]] ; then
+ check_do "do_${DEFAULT_ACTION:-usage}" "$@"
+ else
+ is_function "do_${subaction}" \
+ || die -q "Action ${subaction} unknown"
+ check_do "do_${subaction}" "$@"
+ fi
+ )
}
# inherit module PUBLIC
# Sources a given eselect library file
inherit() {
- local x
- for x in ${@} ; do
- [[ -e "${ESELECT_CORE_PATH}/${x}.bash" ]] \
- || die "Couldn't find ${x}.bash"
- source "${ESELECT_CORE_PATH}/${x}.bash" \
- || die "Couldn't source ${x}.bash"
- done
+ local x
+ for x in ${@} ; do
+ [[ -e "${ESELECT_CORE_PATH}/${x}.bash" ]] \
+ || die "Couldn't find ${x}.bash"
+ source "${ESELECT_CORE_PATH}/${x}.bash" \
+ || die "Couldn't source ${x}.bash"
+ done
}
# make eval not work, because it's evil
eval() {
- die "Don't use eval. Find another way."
+ die "Don't use eval. Find another way."
}
# GNU sed wrapper (real path to GNU sed determined by configure)
sed() {
- @SED@ "$@"
+ @SED@ "$@"
}
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
-
-# vim: set sw=4 et sts=4 tw=80 :
+# vim: set ft=eselect :
diff --git a/libs/default.eselect.in b/libs/default.eselect.in
index c86f034..ed19f81 100644
--- a/libs/default.eselect.in
+++ b/libs/default.eselect.in
@@ -1,6 +1,5 @@
#!/bin/bash
-
-# Copyright (c) 2005 Gentoo Foundation.
+# Copyright (c) 2005-2009 Gentoo Foundation -*-eselect-*-
# $Id$
# This file is part of the 'eselect' tools framework.
#
@@ -21,93 +20,88 @@ VERSION="No version available"
DEFAULT_ACTION="usage"
describe_usage() {
- echo "Display usage information"
+ echo "Display usage information"
}
do_usage() {
- show_usage_message
- if is_function show_extra_help_text ; then
- echo
- echo "Additional help is available via the 'help' action."
- fi
- true
+ show_usage_message
+ if is_function show_extra_help_text ; then
+ echo
+ echo "Additional help is available via the 'help' action."
+ fi
+ true
}
show_usage_message() {
- echo "Usage: ${ESELECT_COMMAND} <action> <options>"
- echo
-
- write_list_start "Standard actions:"
- for action in "help" "usage" "version" ; do
- local desc=""
- is_function "describe_${action}" && desc=$(describe_${action} )
- write_kv_list_entry "${action}" "${desc:-(no description)}"
- done
-
- echo
- write_list_start "Extra actions:"
-
- # FIXME: can we do this using expansion somehow?
- for action in $(set | \
- sed -n -e '/^do_\S\+ ()\s*$/s/^do_\(\S\+\).*/\1/p' | \
- grep -v 'action' | \
- sort ) ; do
- case "${action}" in
- help|usage|version)
- continue
- ;;
- ?*)
- local desc="" line="" ifs_save="${IFS}" action_text=""
- is_function "describe_${action}" && desc=$(describe_${action} )
-
- if is_function "describe_${action}_parameters" ; then
- action_text="${action} $(describe_${action}_parameters)"
- else
- action_text="${action}"
- fi
-
- write_kv_list_entry "${action_text}" "${desc:-(no description)}"
-
- if is_function "describe_${action}_options" ; then
- IFS=$'\n'
- for line in $(describe_${action}_options) ; do
- write_kv_list_entry -p \
- " ${line%%*( ):*}" \
- " ${line##+([^:]):*( )}"
- done
- IFS="${ifs_save}"
- fi
- ;;
- esac
- done
- true
+ echo "Usage: ${ESELECT_COMMAND} <action> <options>"
+ echo
+
+ write_list_start "Standard actions:"
+ for action in "help" "usage" "version" ; do
+ local desc=""
+ is_function "describe_${action}" && desc=$(describe_${action} )
+ write_kv_list_entry "${action}" "${desc:-(no description)}"
+ done
+
+ echo
+ write_list_start "Extra actions:"
+
+ # FIXME: can we do this using expansion somehow?
+ for action in $(set | \
+ sed -n -e '/^do_\S\+ ()\s*$/s/^do_\(\S\+\).*/\1/p' | \
+ grep -v 'action' | \
+ sort ) ; do
+ case "${action}" in
+ help|usage|version)
+ continue
+ ;;
+ ?*)
+ local desc="" line="" ifs_save="${IFS}" action_text=""
+ is_function "describe_${action}" && desc=$(describe_${action} )
+
+ if is_function "describe_${action}_parameters" ; then
+ action_text="${action} $(describe_${action}_parameters)"
+ else
+ action_text="${action}"
+ fi
+
+ write_kv_list_entry "${action_text}" "${desc:-(no description)}"
+
+ if is_function "describe_${action}_options" ; then
+ IFS=$'\n'
+ for line in $(describe_${action}_options) ; do
+ write_kv_list_entry -p \
+ " ${line%%*( ):*}" \
+ " ${line##+([^:]):*( )}"
+ done
+ IFS="${ifs_save}"
+ fi
+ ;;
+ esac
+ done
+ true
}
describe_version() {
- echo "Display version information"
+ echo "Display version information"
}
do_version() {
- echo "Version ${VERSION}"
+ echo "Version ${VERSION}"
}
describe_help() {
- echo "Display help text"
+ echo "Display help text"
}
do_help() {
- echo "${DESCRIPTION}"
- show_usage_message
- if is_function show_extra_help_text ; then
- echo
- show_extra_help_text
- fi
- true
+ echo "${DESCRIPTION}"
+ show_usage_message
+ if is_function show_extra_help_text ; then
+ echo
+ show_extra_help_text
+ fi
+ true
}
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
-
-# vim: set sw=4 et sts=4 tw=80 :
+# vim: set ft=eselect :
diff --git a/libs/editor-variable.bash.in b/libs/editor-variable.bash.in
index 81c5c84..f57659d 100644
--- a/libs/editor-variable.bash.in
+++ b/libs/editor-variable.bash.in
@@ -1,6 +1,5 @@
#!/bin/bash
-
-# Copyright (c) 2009 Gentoo Foundation
+# Copyright (c) 2005-2009 Gentoo Foundation -*-eselect-*-
# $Id$
# This file is part of the 'eselect' tools framework.
#
@@ -31,144 +30,139 @@ inherit config
# find a list of valid targets
find_targets() {
- local cur targets i
- targets=${EDITOR_LIST}
- cur=$(read_env_value)
+ 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}"
+ # 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
+ 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}"
+ 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"
+ [[ -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"
+ echo "Show value of the ${EDITOR_VAR} variable in profile"
}
do_show() {
- [[ $# -gt 0 ]] && die -q "Too many parameters"
+ [[ $# -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)}"
+ 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"
+ 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)"
+ [[ $# -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"
+ echo "Set the ${EDITOR_VAR} variable in profile"
}
describe_set_options() {
- echo "target : Target name or number (from 'list' action)"
+ echo "target : Target name or number (from 'list' action)"
}
describe_set_parameters() {
- echo "<target>"
+ 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
+ [[ -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"
+ echo "Update the ${EDITOR_VAR} variable if it is unset or invalid"
}
do_update() {
- [[ $# -gt 0 ]] && die -q "Too many parameters"
+ [[ $# -gt 0 ]] && die -q "Too many parameters"
- local cur targets
- cur=$(read_env_value)
- [[ -n ${cur} && -f ${ROOT}${cur} ]] && return
+ 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"
+ 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]}"
+ echo "Setting ${EDITOR_VAR} to ${targets[0]} ..."
+ write_env_value "${targets[0]}"
- do_action env update noldconfig
+ do_action env update noldconfig
}
-
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
diff --git a/libs/manip.bash.in b/libs/manip.bash.in
index d28ae45..522f4c4 100644
--- a/libs/manip.bash.in
+++ b/libs/manip.bash.in
@@ -1,6 +1,5 @@
#!/bin/bash
-
-# Copyright (c) 2005 Gentoo Foundation.
+# Copyright (c) 2005-2009 Gentoo Foundation -*-eselect-*-
# $Id$
# This file is part of the 'eselect' tools framework.
#
@@ -21,16 +20,11 @@
# are too lazy to manually update VERSION in modules. Safe to use in global
# scope.
svn_date_to_version() {
- local s=${1}
- s=${s#* }
- s=${s%% *}
- s=${s//-}
- echo "${s}"
+ local s=${1}
+ s=${s#* }
+ s=${s%% *}
+ s=${s//-}
+ echo "${s}"
}
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
-
-# vim: set sw=4 et sts=4 tw=80 :
+# vim: set ft=eselect :
diff --git a/libs/multilib.bash.in b/libs/multilib.bash.in
index 894706a..9871602 100644
--- a/libs/multilib.bash.in
+++ b/libs/multilib.bash.in
@@ -1,6 +1,5 @@
#!/bin/bash
-
-# Copyright (c) 2005 Gentoo Foundation.
+# Copyright (c) 2005-2009 Gentoo Foundation -*-eselect-*-
# $Id$
# This file is part of the 'eselect' tools framework.
#
@@ -21,24 +20,19 @@ ES_VALID_MULTILIB_DIRS="lib lib32 lib64"
# list_libdirs PUBLIC
# Returns a space separated list of libdirs available on this machine
list_libdirs() {
- local dir libdirs
- libdirs=""
- for dir in ${ES_VALID_MULTILIB_DIRS} ; do
- if grep -q "^/${dir}\(\|/\)$" ${ROOT}/etc/ld.so.conf &> /dev/null ; then
- libdirs=( ${libdirs[@]} ${dir} )
- fi
- done
- if [[ -z ${libdirs[@]} ]] ; then
- # Broken or non-existing ld.so.conf
- libdirs=( ${ROOT}/lib* )
- libdirs=( ${libdirs[@]/\/lib/lib} )
- fi
- echo "${libdirs[@]}"
+ local dir libdirs
+ libdirs=""
+ for dir in ${ES_VALID_MULTILIB_DIRS} ; do
+ if grep -q "^/${dir}\(\|/\)$" ${ROOT}/etc/ld.so.conf &> /dev/null ; then
+ libdirs=( ${libdirs[@]} ${dir} )
+ fi
+ done
+ if [[ -z ${libdirs[@]} ]] ; then
+ # Broken or non-existing ld.so.conf
+ libdirs=( ${ROOT}/lib* )
+ libdirs=( ${libdirs[@]/\/lib/lib} )
+ fi
+ echo "${libdirs[@]}"
}
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
-
-# vim: set sw=4 et sts=4 tw=80 :
+# vim: set ft=eselect :
diff --git a/libs/output.bash.in b/libs/output.bash.in
index d98d66c..27a357f 100644
--- a/libs/output.bash.in
+++ b/libs/output.bash.in
@@ -1,6 +1,5 @@
#!/bin/bash
-
-# Copyright (c) 2005-2009 Gentoo Foundation.
+# Copyright (c) 2005-2009 Gentoo Foundation -*-eselect-*-
# $Id$
# This file is part of the 'eselect' tools framework.
#
@@ -18,58 +17,58 @@
# Colours
colours() {
- COLOUR_NORMAL=$(tput sgr0)
- COLOUR_BOLD=$(tput bold)
- COLOUR_HI=$(tput setaf 4)${COLOUR_BOLD}
- COLOUR_WARN=$(tput setaf 1)${COLOUR_BOLD}
- COLOUR_ERROR=${COLOUR_WARN}
- COLOUR_LIST_HEADER=$(tput setaf 2)${COLOUR_BOLD}
- COLOUR_LIST_LEFT=${COLOUR_BOLD}
- COLOUR_LIST_RIGHT=${COLOUR_NORMAL}
+ COLOUR_NORMAL=$(tput sgr0)
+ COLOUR_BOLD=$(tput bold)
+ COLOUR_HI=$(tput setaf 4)${COLOUR_BOLD}
+ COLOUR_WARN=$(tput setaf 1)${COLOUR_BOLD}
+ COLOUR_ERROR=${COLOUR_WARN}
+ COLOUR_LIST_HEADER=$(tput setaf 2)${COLOUR_BOLD}
+ COLOUR_LIST_LEFT=${COLOUR_BOLD}
+ COLOUR_LIST_RIGHT=${COLOUR_NORMAL}
}
# disable all colours
nocolours() {
- COLOUR_NORMAL=""
- COLOUR_BOLD=""
- COLOUR_HI=""
- COLOUR_WARN=""
- COLOUR_ERROR=""
- COLOUR_LIST_HEADER=""
- COLOUR_LIST_LEFT=""
- COLOUR_LIST_RIGHT=""
+ COLOUR_NORMAL=""
+ COLOUR_BOLD=""
+ COLOUR_HI=""
+ COLOUR_WARN=""
+ COLOUR_ERROR=""
+ COLOUR_LIST_HEADER=""
+ COLOUR_LIST_LEFT=""
+ COLOUR_LIST_RIGHT=""
}
# Determine width of terminal and set COLUMNS variable
init_columns() {
- [[ -n ${COLUMNS} ]] || COLUMNS=$(tput cols) || COLUMNS=80
+ [[ -n ${COLUMNS} ]] || COLUMNS=$(tput cols) || COLUMNS=80
}
# write_error_msg PUBLIC
# write an error
write_error_msg() {
- echo -e "${COLOUR_ERROR}!!! Error: ${COLOUR_NORMAL}${*}" 1>&2
+ echo -e "${COLOUR_ERROR}!!! Error: ${COLOUR_NORMAL}${*}" 1>&2
}
# write_warning_msg PUBLIC
# write a warning
write_warning_msg() {
- echo -e "${COLOUR_WARN}!!! Warning: ${COLOUR_NORMAL}${*}" 1>&2
+ echo -e "${COLOUR_WARN}!!! Warning: ${COLOUR_NORMAL}${*}" 1>&2
}
# write_list_start PUBLIC
# Write a list heading. Args may include text highlighting. If -p is passed,
# use 'plain' highlighting.
write_list_start() {
- local colour="${COLOUR_LIST_HEADER}"
- if [[ ${1} == "-p" ]] ; then
- colour=
- shift
- fi
- echo -n -e "${colour}"
- echo -n -e "$(apply_text_highlights "${colour}" "$*")"
- echo -n -e "${COLOUR_NORMAL}"
- echo
+ local colour="${COLOUR_LIST_HEADER}"
+ if [[ ${1} == "-p" ]] ; then
+ colour=
+ shift
+ fi
+ echo -n -e "${colour}"
+ echo -n -e "$(apply_text_highlights "${colour}" "$*")"
+ echo -n -e "${COLOUR_NORMAL}"
+ echo
}
# write_kv_list_entry PUBLIC
@@ -77,156 +76,151 @@ write_list_start() {
# Args may include text highlighting. If -p is passed, use 'plain'
# highlighting rather than bold.
write_kv_list_entry() {
- local n text left="${COLOUR_LIST_LEFT}" right="${COLOUR_LIST_RIGHT}"
- local key val lindent rindent ifs_save="${IFS}"
-
- IFS=$' \t\n'
-
- if [[ ${1} == "-p" ]] ; then
- left=
- right=
- shift
- fi
-
- lindent=${1%%[^[:space:]]*}
- rindent=${2%%[^[:space:]]*}
- key=${1##*([[:space:]])}
- val=${2##*([[:space:]])}
-
- echo -n -e " ${lindent}${left}"
- echo -n -e "$(apply_text_highlights "${left}" "${key}")"
- echo -n -e "${COLOUR_NORMAL} "
-
- text=${key//\%%%??%%%/}
- n=$(( 25 - ${#text} ))
-
- # if ${n} is less than or equal to zero then we have a long ${key}
- # that will mess up the formatting of ${val}, so end the line, indent
- # and let ${val} go on the next line.
- if [[ ${n} -le 0 ]] ; then
- n=$(( ${#rindent} + 28 ))
- echo -n -e "\n$(space ${n})${right}"
- else
- space ${n}
- n=$(( ${n} + 2 + ${#text} ))
- # ${val} will already be indented by ${lindent} so only use the
- # difference of ${rindent} and ${lindent} as the right indent
- if [[ ${#rindent} -eq ${#lindent} ]] ; then
- n=$(( ${n} + ${#lindent} ))
- else
- space $(( ${#rindent} - ${#lindent} ))
- n=$(( ${n} + ${#rindent} - ${#lindent} ))
- fi
- echo -n -e "${right}"
- fi
-
- local cols=${COLUMNS:-80}
- local cwords="$(apply_text_highlights "${right}" "${val}")"
-
- text=${val//\%%%??%%%/}
- # only loop if it doesn't fit on the same line
- if [[ $(( ${n} + ${#text} )) -ge ${cols} ]] ; then
- local i=0 spc=""
- rindent="${rindent}$(space 28)"
- cwords=( ${cwords} )
- for text in ${val} ; do
- text=${text//\%%%??%%%/}
- # put the word on the same line if it fits
- if [[ $(( ${n} + ${#spc} + ${#text} )) -lt ${cols} ]] ; then
- echo -n -e "${spc}${cwords[i]}"
- n=$(( ${n} + ${#spc} + ${#text} ))
- # otherwise, start a new line and indent
- else
- echo -n -e "\n${rindent}${cwords[i]}"
- n=$(( ${#rindent} + ${#text} ))
- fi
- i=$(( ${i} + 1 ))
- spc=" "
- done
- else
- echo -n -e "${cwords}"
- fi
- echo -e "${COLOUR_NORMAL}"
- IFS="${ifs_save}"
+ local n text left="${COLOUR_LIST_LEFT}" right="${COLOUR_LIST_RIGHT}"
+ local key val lindent rindent ifs_save="${IFS}"
+
+ IFS=$' \t\n'
+
+ if [[ ${1} == "-p" ]] ; then
+ left=
+ right=
+ shift
+ fi
+
+ lindent=${1%%[^[:space:]]*}
+ rindent=${2%%[^[:space:]]*}
+ key=${1##*([[:space:]])}
+ val=${2##*([[:space:]])}
+
+ echo -n -e " ${lindent}${left}"
+ echo -n -e "$(apply_text_highlights "${left}" "${key}")"
+ echo -n -e "${COLOUR_NORMAL} "
+
+ text=${key//\%%%??%%%/}
+ n=$(( 25 - ${#text} ))
+
+ # if ${n} is less than or equal to zero then we have a long ${key}
+ # that will mess up the formatting of ${val}, so end the line, indent
+ # and let ${val} go on the next line.
+ if [[ ${n} -le 0 ]] ; then
+ n=$(( ${#rindent} + 28 ))
+ echo -n -e "\n$(space ${n})${right}"
+ else
+ space ${n}
+ n=$(( ${n} + 2 + ${#text} ))
+ # ${val} will already be indented by ${lindent} so only use the
+ # difference of ${rindent} and ${lindent} as the right indent
+ if [[ ${#rindent} -eq ${#lindent} ]] ; then
+ n=$(( ${n} + ${#lindent} ))
+ else
+ space $(( ${#rindent} - ${#lindent} ))
+ n=$(( ${n} + ${#rindent} - ${#lindent} ))
+ fi
+ echo -n -e "${right}"
+ fi
+
+ local cols=${COLUMNS:-80}
+ local cwords="$(apply_text_highlights "${right}" "${val}")"
+
+ text=${val//\%%%??%%%/}
+ # only loop if it doesn't fit on the same line
+ if [[ $(( ${n} + ${#text} )) -ge ${cols} ]] ; then
+ local i=0 spc=""
+ rindent="${rindent}$(space 28)"
+ cwords=( ${cwords} )
+ for text in ${val} ; do
+ text=${text//\%%%??%%%/}
+ # put the word on the same line if it fits
+ if [[ $(( ${n} + ${#spc} + ${#text} )) -lt ${cols} ]] ; then
+ echo -n -e "${spc}${cwords[i]}"
+ n=$(( ${n} + ${#spc} + ${#text} ))
+ # otherwise, start a new line and indent
+ else
+ echo -n -e "\n${rindent}${cwords[i]}"
+ n=$(( ${#rindent} + ${#text} ))
+ fi
+ i=$(( ${i} + 1 ))
+ spc=" "
+ done
+ else
+ echo -n -e "${cwords}"
+ fi
+ echo -e "${COLOUR_NORMAL}"
+ IFS="${ifs_save}"
}
# write_numbered_list_entry PUBLIC
# Write out a numbered list entry with index $1 and text $2. Args may
# include text highlighting. If -p is passed, use 'plain' highlighting.
write_numbered_list_entry() {
- local n left="${COLOUR_LIST_LEFT}" right="${COLOUR_LIST_RIGHT}"
- if [[ ${1} == "-p" ]] ; then
- left=""
- right=""
- shift
- fi
- echo -n -e " ${left}"
- echo -n -e "[$(apply_text_highlights "${left}" "$1")]"
- echo -n -e "${COLOUR_NORMAL}"
- space $(( 4 - ${#1} ))
- echo -n -e "${right}"
- echo -n -e "$(apply_text_highlights "${right}" "$2")"
- echo -n -e "${COLOUR_NORMAL}"
- echo
+ local n left="${COLOUR_LIST_LEFT}" right="${COLOUR_LIST_RIGHT}"
+ if [[ ${1} == "-p" ]] ; then
+ left=""
+ right=""
+ shift
+ fi
+ echo -n -e " ${left}"
+ echo -n -e "[$(apply_text_highlights "${left}" "$1")]"
+ echo -n -e "${COLOUR_NORMAL}"
+ space $(( 4 - ${#1} ))
+ echo -n -e "${right}"
+ echo -n -e "$(apply_text_highlights "${right}" "$2")"
+ echo -n -e "${COLOUR_NORMAL}"
+ echo
}
# write_numbered_list PUBLIC
# Write out a numbered list. Args may include text highlighting.
write_numbered_list() {
- local n=1 p=
- if [[ ${1} == "-p" ]] ; then
- p="-p"
- shift
- fi
-
- while [[ ${#@} -gt 0 ]] ; do
- item=${1}
- shift
- if [[ ${item##*\\} == "" ]] ; then
- item="${item%\\} ${1}"
- shift
- fi
- write_numbered_list_entry ${p} "${n}" "${item}"
- n=$(( ${n} + 1 ))
- done
+ local n=1 p=
+ if [[ ${1} == "-p" ]] ; then
+ p="-p"
+ shift
+ fi
+
+ while [[ ${#@} -gt 0 ]] ; do
+ item=${1}
+ shift
+ if [[ ${item##*\\} == "" ]] ; then
+ item="${item%\\} ${1}"
+ shift
+ fi
+ write_numbered_list_entry ${p} "${n}" "${item}"
+ n=$(( ${n} + 1 ))
+ done
}
# apply_text_highlights INTERNAL
# Apply text highlights. First arg is the 'restore' colour, second arg
# is the text.
apply_text_highlights() {
- local restore=${1} text=${2}
- text="${text//?%%HI%%%/${COLOUR_HI}}"
- text="${text//?%%WA%%%/${COLOUR_WARN}}"
- text="${text//?%%RE%%%/${restore}}"
- echo -n "${text}"
+ local restore=${1} text=${2}
+ text="${text//?%%HI%%%/${COLOUR_HI}}"
+ text="${text//?%%WA%%%/${COLOUR_WARN}}"
+ text="${text//?%%RE%%%/${restore}}"
+ echo -n "${text}"
}
# highlight PUBLIC
# Highlight all arguments. Text highlighting function.
highlight() {
- echo -n -e "%%%HI%%%${*}%%%RE%%%"
+ echo -n -e "%%%HI%%%${*}%%%RE%%%"
}
# highlight_warning PUBLIC
# Highlight all arguments as a warning (red). Text highlighting function.
highlight_warning() {
- echo -n -e "%%%WA%%%${*}%%%RE%%%"
+ echo -n -e "%%%WA%%%${*}%%%RE%%%"
}
# space PUBLIC
# Write $1 numbers of spaces
space() {
- local ret=""
- for (( n = 1 ; n <= ${1} ; ++n )) ; do
- ret="${ret} "
- done
- echo -n "${ret}"
+ local ret=""
+ for (( n = 1 ; n <= ${1} ; ++n )) ; do
+ ret="${ret} "
+ done
+ echo -n "${ret}"
}
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
-
-# vim: set sw=4 et sts=4 tw=80 :
+# vim: set ft=eselect :
diff --git a/libs/package-manager.bash.in b/libs/package-manager.bash.in
index f4d2d52..badfad8 100644
--- a/libs/package-manager.bash.in
+++ b/libs/package-manager.bash.in
@@ -1,6 +1,5 @@
#!/bin/bash
-
-# Copyright (c) 2005-2009 Gentoo Foundation.
+# Copyright (c) 2005-2009 Gentoo Foundation -*-eselect-*-
# $Id$
# This file is part of the 'eselect' tools framework.
#
@@ -19,139 +18,134 @@
# package-manager PRIVATE
# Return the package manager we're going to use.
package-manager() {
- echo "${ESELECT_PACKAGE_MANAGER:-@PACKAGE_MANAGER@}"
+ echo "${ESELECT_PACKAGE_MANAGER:-@PACKAGE_MANAGER@}"
}
# portageq
# Run portageq with safe filename as set by configure. Redirect stderr
portageq() {
- @PORTAGEQ@ "$@" 2>/dev/null
+ @PORTAGEQ@ "$@" 2>/dev/null
}
# paludis
# Run PALUDIS_COMMAND (defaults to "paludis"). Redirect stderr
paludis() {
- ${PALUDIS_COMMAND:-paludis} "$@" 2>/dev/null
+ ${PALUDIS_COMMAND:-paludis} "$@" 2>/dev/null
}
# arch
# Return the architecture we're running on...
arch() {
- local ret=$(envvar sys-devel/gcc ARCH) suffix
-
- # $arch will be null if there's no current make.profile symlink
- # we cannot get a list of valid profiles without it.
- if [[ -z ${ret} ]] ; then
-
- if [[ -n ${ROOT} && ${ROOT} != "/" ]] ; then
- write_warning_msg "Failed to determine \${ARCH}. Is your make.profile symlink valid?"
- return 1
- fi
-
- case $(uname -m) in
- alpha|ia64|ppc) ;;
- i?86) ret=x86 ;;
- mips*) ret=mips ;;
- sparc*) ret=sparc ;;
- x86_64) ret=amd64 ;;
- "Power Macintosh") ret=ppc ;;
- *) write_warning_msg \
- "Unknown architecture. Please submit a bug including the output of 'uname -m'"
- return 1
- ;;
- esac
-
- case $(uname -s) in
- Linux) ;;
- FreeBSD) suffix="-fbsd" ;;
- NetBSD) suffix="-nbsd" ;;
- OpenBSD) suffix="-obsd" ;;
- DragonFly) suffix="-dfly" ;;
- Darwin) suffix="-macos" ;;
- *) write_warning_msg \
- "Unknown OS. Please submit a bug including the output of 'uname -s'"
- return 1
- ;;
- esac
- fi
-
- echo ${ret}${suffix}
+ local ret=$(envvar sys-devel/gcc ARCH) suffix
+
+ # $arch will be null if there's no current make.profile symlink
+ # we cannot get a list of valid profiles without it.
+ if [[ -z ${ret} ]] ; then
+
+ if [[ -n ${ROOT} && ${ROOT} != "/" ]] ; then
+ write_warning_msg "Failed to determine \${ARCH}. Is your make.profile symlink valid?"
+ return 1
+ fi
+
+ case $(uname -m) in
+ alpha|ia64|ppc) ;;
+ i?86) ret=x86 ;;
+ mips*) ret=mips ;;
+ sparc*) ret=sparc ;;
+ x86_64) ret=amd64 ;;
+ "Power Macintosh") ret=ppc ;;
+ *) write_warning_msg \
+ "Unknown architecture. Please submit a bug including the output of 'uname -m'"
+ return 1
+ ;;
+ esac
+
+ case $(uname -s) in
+ Linux) ;;
+ FreeBSD) suffix="-fbsd" ;;
+ NetBSD) suffix="-nbsd" ;;
+ OpenBSD) suffix="-obsd" ;;
+ DragonFly) suffix="-dfly" ;;
+ Darwin) suffix="-macos" ;;
+ *) write_warning_msg \
+ "Unknown OS. Please submit a bug including the output of 'uname -s'"
+ return 1
+ ;;
+ esac
+ fi
+
+ echo ${ret}${suffix}
}
# envvar
# Return the contents of environment variable $2 as seen by package manager
# for package $1.
envvar() {
- [[ $# -eq 2 ]] || die "envvar expects exactly 2 arguments"
- local manager=$(package-manager)
- case ${manager} in
- # portage does not support per-package envvar lookup
- portage) portageq envvar "$2" ;;
- paludis) paludis --environment-variable "$1" "$2" ;;
- *) die "Unknown package manager: \"${manager}\"" ;;
- esac
+ [[ $# -eq 2 ]] || die "envvar expects exactly 2 arguments"
+ local manager=$(package-manager)
+ case ${manager} in
+ # portage does not support per-package envvar lookup
+ portage) portageq envvar "$2" ;;
+ paludis) paludis --environment-variable "$1" "$2" ;;
+ *) die "Unknown package manager: \"${manager}\"" ;;
+ esac
}
# best_version
# Return true if package $1 is available in ${ROOT}
best_version() {
- [[ $# -eq 1 ]] || die "best_version expects exactly one argument"
- local manager=$(package-manager)
- case ${manager} in
- portage) portageq best_version "${ROOT:-/}" "$1" ;;
- paludis) paludis --best-version "$1" ;;
- *) die "Unknown package manager: \"${manager}\"" ;;
- esac
+ [[ $# -eq 1 ]] || die "best_version expects exactly one argument"
+ local manager=$(package-manager)
+ case ${manager} in
+ portage) portageq best_version "${ROOT:-/}" "$1" ;;
+ paludis) paludis --best-version "$1" ;;
+ *) die "Unknown package manager: \"${manager}\"" ;;
+ esac
}
# has_version
# Return true if package $1 is available in ${ROOT}
has_version() {
- [[ $# -eq 1 ]] || die "has_version expects exactly one argument"
- local manager=$(package-manager)
- case ${manager} in
- portage) portageq has_version "${ROOT:-/}" "$1" ;;
- paludis) paludis --has-version "$1" ;;
- *) die "Unknown package manager: \"${manager}\"" ;;
- esac
+ [[ $# -eq 1 ]] || die "has_version expects exactly one argument"
+ local manager=$(package-manager)
+ case ${manager} in
+ portage) portageq has_version "${ROOT:-/}" "$1" ;;
+ paludis) paludis --has-version "$1" ;;
+ *) die "Unknown package manager: \"${manager}\"" ;;
+ esac
}
# get_repositories
# return list of repositories known to the package manager
get_repositories() {
- local manager=$(package-manager)
- case ${manager} in
- portage) portageq get_repos "${ROOT:-/}" ;;
- paludis) paludis --list-repositories | cut -d' ' -f 2 ;;
- *) die "Unknown package manager: \"${manager}\"" ;;
- esac
+ local manager=$(package-manager)
+ case ${manager} in
+ portage) portageq get_repos "${ROOT:-/}" ;;
+ paludis) paludis --list-repositories | cut -d' ' -f 2 ;;
+ *) die "Unknown package manager: \"${manager}\"" ;;
+ esac
}
# get_repo_news_dir
# return the directory where to find GLEP 42 news items for repository $1
get_repo_news_dir() {
- [[ $# -eq 1 ]] || die "get_repo_news_dir expects exactly one argument"
- local repo=$1
- local manager=$(package-manager)
- case ${manager} in
- portage)
- echo "$(portageq get_repo_path \
- "${ROOT:-/}" "${repo}")/metadata/news" ;;
- paludis) paludis --configuration-variable ${repo} newsdir ;;
- *) die "Unknown package manager: \"${manager}\"" ;;
- esac
+ [[ $# -eq 1 ]] || die "get_repo_news_dir expects exactly one argument"
+ local repo=$1
+ local manager=$(package-manager)
+ case ${manager} in
+ portage)
+ echo "$(portageq get_repo_path \
+ "${ROOT:-/}" "${repo}")/metadata/news" ;;
+ paludis) paludis --configuration-variable ${repo} newsdir ;;
+ *) die "Unknown package manager: \"${manager}\"" ;;
+ esac
}
# get_news_dir_name DEPRECATED
get_news_dir_name() {
- [[ $# -eq 1 ]] || die "get_news_dir_name expects exactly one argument"
- local name=${1%::*} repo=${1##*::}
- echo "$(get_repo_news_dir "${repo}")/${name}"
+ [[ $# -eq 1 ]] || die "get_news_dir_name expects exactly one argument"
+ local name=${1%::*} repo=${1##*::}
+ echo "$(get_repo_news_dir "${repo}")/${name}"
}
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
-
-# vim: set sw=4 et sts=4 tw=80 :
+# vim: set ft=eselect :
diff --git a/libs/path-manipulation.bash.in b/libs/path-manipulation.bash.in
index 25ee0c3..84f57e2 100644
--- a/libs/path-manipulation.bash.in
+++ b/libs/path-manipulation.bash.in
@@ -1,6 +1,5 @@
#!/bin/bash
-
-# Copyright (c) 2005-2009 Gentoo Foundation.
+# Copyright (c) 2005-2009 Gentoo Foundation -*-eselect-*-
# $Id$
# This file is part of the 'eselect' tools framework.
#
@@ -18,21 +17,16 @@
# basename wrapper
basename() {
- echo "${1##*/}"
+ echo "${1##*/}"
}
# dirname wrapper
dirname() {
- echo "${1%/*}"
+ echo "${1%/*}"
}
canonicalise() {
- @CANONICALISE@ "$@"
+ @CANONICALISE@ "$@"
}
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
-
-# vim: set sw=4 et sts=4 tw=80 :
+# vim: set ft=eselect :
diff --git a/libs/skel.bash.in b/libs/skel.bash.in
index 3930ffa..24f44b6 100644
--- a/libs/skel.bash.in
+++ b/libs/skel.bash.in
@@ -1,6 +1,19 @@
-# Copyright 1999-2009 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
+#!/bin/bash
+# Copyright (c) 1999-2009 Gentoo Foundation -*-eselect-*-
# $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/>.
# To use this library, you must set MODULE and IFACE.
# MODULE is the name you use to refer to whatever it is that you're selecting
@@ -23,295 +36,290 @@ inherit config multilib tests
# find_implems $iface $libdir
# find all possible implems for $libdir
find_implems() {
- local -a implems
- iface=$1 libdir=$2
- for file in ${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/* ; do
- [[ -f ${file} ]] || continue
- [[ "${file##*/}" != "config" ]] || continue
- implems=(${implems[@]} "${file##*/}")
- done
- echo ${implems[@]}
+ local -a implems
+ iface=$1 libdir=$2
+ for file in ${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/* ; do
+ [[ -f ${file} ]] || continue
+ [[ "${file##*/}" != "config" ]] || continue
+ implems=(${implems[@]} "${file##*/}")
+ done
+ echo ${implems[@]}
}
# is_active $iface $libdir $implem
# returns true if $implem is currently used for the $iface/$libdir combination
is_active() {
- [[ ${#@} -eq 3 ]] || die "Need exactly 3 arguments!"
- current=$(load_config ${ROOT}@sysconfdir@/env.d/${1}/${2}/config CURRENT)
- [[ ${current} == ${3} ]]
+ [[ ${#@} -eq 3 ]] || die "Need exactly 3 arguments!"
+ current=$(load_config ${ROOT}@sysconfdir@/env.d/${1}/${2}/config CURRENT)
+ [[ ${current} == ${3} ]]
}
# switch_implem $iface $libdir $implem
# switches $iface/$libdir combination to $implem
switch_implem() {
- # set us up
- [[ ${#@} -eq 3 ]] || die "Need exactly 3 arguments!"
- local iface=${1}
- local libdir=${2}
- local implem=${3##*/}
- local implem_file=${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/${implem}
- local current=$(load_config \
- "${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/config" CURRENT)
- local current_file=${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/${current}
- local dest src
-
- # Get rid of old symlinks, if we have a current config
- if [[ -f "${current_file}" ]]; then
- while read line; do
- # Skip comments
- [[ "${line}" = *#* ]] && continue
-
- line=${line//@LIBDIR@/${libdir}}
-
- set ${line}
- dest=$2
- rm -f ${ROOT}${dest}
- done < ${current_file}
- fi
-
- # Set up new symlinks
- while read line; do
- # Skip comments
- [[ "${line}" = *#* ]] && continue
-
- line=${line//@LIBDIR@/${libdir}}
-
- set ${line}
- src=$1
- dest=$2
- ln -sf ${src} ${ROOT}${dest}
- done < ${implem_file}
-
- store_config \
- "${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/config" \
- CURRENT ${implem}
+ # set us up
+ [[ ${#@} -eq 3 ]] || die "Need exactly 3 arguments!"
+ local iface=${1}
+ local libdir=${2}
+ local implem=${3##*/}
+ local implem_file=${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/${implem}
+ local current=$(load_config \
+ "${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/config" CURRENT)
+ local current_file=${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/${current}
+ local dest src
+
+ # Get rid of old symlinks, if we have a current config
+ if [[ -f "${current_file}" ]]; then
+ while read line; do
+ # Skip comments
+ [[ "${line}" = *#* ]] && continue
+
+ line=${line//@LIBDIR@/${libdir}}
+
+ set ${line}
+ dest=$2
+ rm -f ${ROOT}${dest}
+ done < ${current_file}
+ fi
+
+ # Set up new symlinks
+ while read line; do
+ # Skip comments
+ [[ "${line}" = *#* ]] && continue
+
+ line=${line//@LIBDIR@/${libdir}}
+
+ set ${line}
+ src=$1
+ dest=$2
+ ln -sf ${src} ${ROOT}${dest}
+ done < ${implem_file}
+
+ store_config \
+ "${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/config" \
+ CURRENT ${implem}
}
# iface_do_list $libdir
# Lists the available implementations for $libdir
iface_do_list() {
- local -a implems
- local active libdir=$1 iface=$IFACE
- implems=( $(find_implems $iface $libdir ) )
-
- # None installed for $libdir
- [[ -z ${implems[@]} ]] \
- && return
-
- write_list_start "Installed $MODULE for library directory $(highlight ${libdir})"
- for implem in ${implems[@]} ; do
- (( i++ ))
- active=''
- is_active ${iface} ${libdir} ${implem##*/} \
- && active=' *'
-
- write_numbered_list_entry $i "${implem}$(highlight "${active}")"
- done
+ local -a implems
+ local active libdir=$1 iface=$IFACE
+ implems=( $(find_implems $iface $libdir ) )
+
+ # None installed for $libdir
+ [[ -z ${implems[@]} ]] \
+ && return
+
+ write_list_start "Installed $MODULE for library directory $(highlight ${libdir})"
+ for implem in ${implems[@]} ; do
+ (( i++ ))
+ active=''
+ is_active ${iface} ${libdir} ${implem##*/} \
+ && active=' *'
+
+ write_numbered_list_entry $i "${implem}$(highlight "${active}")"
+ done
}
# iface_do_show $libdir
# Shows the current implementation for $libdir
iface_do_show() {
- local iface=$IFACE libdir=$1 implem
- config=${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/config
- [[ ${#config[@]} -eq 1 ]] \
- || return
- [[ -e ${config} ]] \
- || return
-
- implem=$(load_config \
- "${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/config" CURRENT)
- [[ -e ${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/${implem} ]] \
- || die "File \"${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/${implem}\" is missing!"
-
- echo "${libdir}: ${implem}"
+ local iface=$IFACE libdir=$1 implem
+ config=${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/config
+ [[ ${#config[@]} -eq 1 ]] \
+ || return
+ [[ -e ${config} ]] \
+ || return
+
+ implem=$(load_config \
+ "${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/config" CURRENT)
+ [[ -e ${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/${implem} ]] \
+ || die "File \"${ROOT}@sysconfdir@/env.d/${iface}/${libdir}/${implem}\" is missing!"
+
+ echo "${libdir}: ${implem}"
}
# get_libdirs
# Wraps list_libdirs() to ensure that output is sorted consistently
get_libdirs() {
- list_libdirs | sort
+ list_libdirs | sort
}
### list action
describe_list() {
- echo "List all installed $MODULE implementations"
+ echo "List all installed $MODULE implementations"
}
do_list() {
- local libdir
- # Count for listing IFACE/libdir combinations
- # We keep it here so it doesn't reset on every call to iface_do_list()
- local i=0
-
- for libdir in $(get_libdirs); do
- [[ -d ${ROOT}@prefix@/${libdir} ]] \
- && [[ ! -h ${ROOT}@prefix@/${libdir} ]] \
- || continue
- iface_do_list $libdir
- done
+ local libdir
+ # Count for listing IFACE/libdir combinations
+ # We keep it here so it doesn't reset on every call to iface_do_list()
+ local i=0
+
+ for libdir in $(get_libdirs); do
+ [[ -d ${ROOT}@prefix@/${libdir} ]] \
+ && [[ ! -h ${ROOT}@prefix@/${libdir} ]] \
+ || continue
+ iface_do_list $libdir
+ done
}
### set action
describe_set() {
- echo "Activate one of the installed $MODULE implementations"
+ echo "Activate one of the installed $MODULE implementations"
}
describe_set_parameters() {
- echo "<implementation>"
+ echo "<implementation>"
}
describe_set_options() {
- echo "implementation : implementation name or number (from 'list' action)"
+ echo "implementation : implementation name or number (from 'list' action)"
}
do_set() {
- [[ ${#@} == 0 ]] \
- && die -q "Please specify exactly 1 implementation!"
- local fail=0 iface=$IFACE
- local libdirs=$(get_libdirs)
- local libdir implem libdir_ct i=0
- local -a file implems new_implems mylibdirs myimplems
-
- # Build up list of all valid implems
- for libdir in ${libdirs}; do
- new_implems=( $(find_implems ${iface} ${libdir}) )
- implems=( ${implems[@]} ${new_implems[@]} )
- libdir_ct[$i]=${#new_implems[@]}
- (( i++ ))
- done
-
- # Parse passed parameters into valid libdirs. Other arguments are considered
- # implementations (or numbers for them) and are validated later.
- # If libdirs are specified, then switch for them. Otherwise, switch for all
- # libdirs.
- for param in ${@} ; do
- if has ${param} ${libdirs} ; then
- mylibdirs=(${mylibdirs[@]} ${param})
- else
- myimplems=(${myimplems[@]} ${param})
- fi
- done
- set ${myimplems[@]}
-
- # We can only change one implem at a time
- [[ ${#myimplems[@]} -ne 1 ]] && \
- die -q "Please specify exactly 1 implemention."
-
- [[ -n ${mylibdirs[@]} ]] && libdirs=${mylibdirs[@]}
-
- i=0
- for libdir in ${libdirs}; do
- # Only move on if we actually have implems here, otherwise we screw up
- # $libdir_max and waste time executing pointless code
- if [[ ${libdir_ct[$i]} -gt 0 ]]; then
- for item in ${@} ; do
- if is_number ${item} ; then
- # On the first libdir, minimum must be 1. Maxes and later
- # mins are incremented by the size of the previous libdir_ct
- if [[ -n ${libdir_min} ]]; then
- libdir_min=$(( ${libdir_min} + ${libdir_ct[$(( $i - 1 ))]} ))
- else
- libdir_min="1"
- fi
- libdir_max=$(( ${libdir_min} + ${libdir_ct[$i]} - 1 ))
- if [[ ${item} -ge ${libdir_min} ]] && [[ ${item} -le ${libdir_max} ]] ; then
- if ! switch_implem ${iface} ${libdir} ${implems[$(( ${item} -1 ))]}; then
- fail=1
- echo "Failed to switch to implementation \"${item}\" for library directory \"${libdir}\"!"
- continue
- fi
- else
- fail=1
- echo "Item not in range ${libdir_min}-${libdir_max} for ${libdir}: ${item}"
- continue
- fi
- else
- # Only attempt to switch to an implementation if it's available
- # for that libdir
- if has ${item} $(find_implems ${iface} ${libdir}); then
- if ! switch_implem ${iface} ${libdir} ${item}; then
- fail=1
- echo "Failed to switch to implementation \"${item}\" for library directory \"${libdir}\"!"
- continue
- fi
- fi
- fi
- done
- fi
- (( i++ ))
- done
-
- [[ ${fail} == 1 ]] && die -q "One or more actions have failed!"
+ [[ ${#@} == 0 ]] \
+ && die -q "Please specify exactly 1 implementation!"
+ local fail=0 iface=$IFACE
+ local libdirs=$(get_libdirs)
+ local libdir implem libdir_ct i=0
+ local -a file implems new_implems mylibdirs myimplems
+
+ # Build up list of all valid implems
+ for libdir in ${libdirs}; do
+ new_implems=( $(find_implems ${iface} ${libdir}) )
+ implems=( ${implems[@]} ${new_implems[@]} )
+ libdir_ct[$i]=${#new_implems[@]}
+ (( i++ ))
+ done
+
+ # Parse passed parameters into valid libdirs. Other arguments are considered
+ # implementations (or numbers for them) and are validated later.
+ # If libdirs are specified, then switch for them. Otherwise, switch for all
+ # libdirs.
+ for param in ${@} ; do
+ if has ${param} ${libdirs} ; then
+ mylibdirs=(${mylibdirs[@]} ${param})
+ else
+ myimplems=(${myimplems[@]} ${param})
+ fi
+ done
+ set ${myimplems[@]}
+
+ # We can only change one implem at a time
+ [[ ${#myimplems[@]} -ne 1 ]] && \
+ die -q "Please specify exactly 1 implemention."
+
+ [[ -n ${mylibdirs[@]} ]] && libdirs=${mylibdirs[@]}
+
+ i=0
+ for libdir in ${libdirs}; do
+ # Only move on if we actually have implems here, otherwise we screw up
+ # $libdir_max and waste time executing pointless code
+ if [[ ${libdir_ct[$i]} -gt 0 ]]; then
+ for item in ${@} ; do
+ if is_number ${item} ; then
+ # On the first libdir, minimum must be 1. Maxes and later
+ # mins are incremented by the size of the previous libdir_ct
+ if [[ -n ${libdir_min} ]]; then
+ libdir_min=$(( ${libdir_min} + ${libdir_ct[$(( $i - 1 ))]} ))
+ else
+ libdir_min="1"
+ fi
+ libdir_max=$(( ${libdir_min} + ${libdir_ct[$i]} - 1 ))
+ if [[ ${item} -ge ${libdir_min} ]] && [[ ${item} -le ${libdir_max} ]] ; then
+ if ! switch_implem ${iface} ${libdir} ${implems[$(( ${item} -1 ))]}; then
+ fail=1
+ echo "Failed to switch to implementation \"${item}\" for library directory \"${libdir}\"!"
+ continue
+ fi
+ else
+ fail=1
+ echo "Item not in range ${libdir_min}-${libdir_max} for ${libdir}: ${item}"
+ continue
+ fi
+ else
+ # Only attempt to switch to an implementation if it's available
+ # for that libdir
+ if has ${item} $(find_implems ${iface} ${libdir}); then
+ if ! switch_implem ${iface} ${libdir} ${item}; then
+ fail=1
+ echo "Failed to switch to implementation \"${item}\" for library directory \"${libdir}\"!"
+ continue
+ fi
+ fi
+ fi
+ done
+ fi
+ (( i++ ))
+ done
+
+ [[ ${fail} == 1 ]] && die -q "One or more actions have failed!"
}
### show action
describe_show() {
- echo "Print the currently active $MODULE implementation"
+ echo "Print the currently active $MODULE implementation"
}
do_show() {
- local libdir
- local libdirs=$(get_libdirs)
- for param in ${@} ; do
- if has ${param} ${libdirs} ; then
- mylibdirs=(${mylibdirs[@]} ${param})
- fi
- done
- [[ -n ${mylibdirs[@]} ]] && libdirs=${mylibdirs[@]}
-
- for libdir in ${libdirs}; do
- [[ -d ${ROOT}@prefix@/${libdir} ]] \
- && [[ ! -h ${ROOT}@prefix@/${libdir} ]] \
- || continue
- iface_do_show $libdir
- done
+ local libdir
+ local libdirs=$(get_libdirs)
+ for param in ${@} ; do
+ if has ${param} ${libdirs} ; then
+ mylibdirs=(${mylibdirs[@]} ${param})
+ fi
+ done
+ [[ -n ${mylibdirs[@]} ]] && libdirs=${mylibdirs[@]}
+
+ for libdir in ${libdirs}; do
+ [[ -d ${ROOT}@prefix@/${libdir} ]] \
+ && [[ ! -h ${ROOT}@prefix@/${libdir} ]] \
+ || continue
+ iface_do_show $libdir
+ done
}
### add action
describe_add() {
- echo "Add a new $MODULE implementation"
+ echo "Add a new $MODULE implementation"
}
describe_add_parameters() {
- echo "<libdir> <file> <implementation>"
+ echo "<libdir> <file> <implementation>"
}
describe_add_options() {
- echo "libdir : library directory where $MODULE implementation is installed (lib, lib64, etc.)"
- echo "file : path to file containing symlink map"
- echo "implementation : name of the $MODULE implementation"
+ echo "libdir : library directory where $MODULE implementation is installed (lib, lib64, etc.)"
+ echo "file : path to file containing symlink map"
+ echo "implementation : name of the $MODULE implementation"
}
do_add() {
- [[ ${#@} -ne 3 ]] \
- && die -q "Please specify 1 library directory, 1 file to install and 1 implementation!"
-
- # If $D is set, we're adding from portage so we want to respect sandbox.
- # Otherwise, respect the ROOT variable.
- local PREFIX=${D:-${ROOT}}
-
- # Create directory if necessary
- if [[ ! -e ${PREFIX}@sysconfdir@/env.d/${IFACE}/${1} ]]; then
- mkdir -p "${PREFIX}@sysconfdir@/env.d/${IFACE}/${1}"
- else
- if [[ ! -d ${PREFIX}@sysconfdir@/env.d/${IFACE}/${1} ]]; then
- die -q "${PREFIX}@sysconfdir@/env.d/${IFACE}/${1} exists but isn't a directory!"
- fi
- fi
-
- if ! cp ${2} "${PREFIX}@sysconfdir@/env.d/${IFACE}/${1}/${3}"; then
- die -q "Installing ${2} as ${PREFIX}@sysconfdir@/env.d/${IFACE}/${1}/${3} failed!"
- fi
+ [[ ${#@} -ne 3 ]] \
+ && die -q "Please specify 1 library directory, 1 file to install and 1 implementation!"
+
+ # If $D is set, we're adding from portage so we want to respect sandbox.
+ # Otherwise, respect the ROOT variable.
+ local PREFIX=${D:-${ROOT}}
+
+ # Create directory if necessary
+ if [[ ! -e ${PREFIX}@sysconfdir@/env.d/${IFACE}/${1} ]]; then
+ mkdir -p "${PREFIX}@sysconfdir@/env.d/${IFACE}/${1}"
+ else
+ if [[ ! -d ${PREFIX}@sysconfdir@/env.d/${IFACE}/${1} ]]; then
+ die -q "${PREFIX}@sysconfdir@/env.d/${IFACE}/${1} exists but isn't a directory!"
+ fi
+ fi
+
+ if ! cp ${2} "${PREFIX}@sysconfdir@/env.d/${IFACE}/${1}/${3}"; then
+ die -q "Installing ${2} as ${PREFIX}@sysconfdir@/env.d/${IFACE}/${1}/${3} failed!"
+ fi
}
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
-
-# vim: set sw=4 et sts=4 tw=80 :
+# vim: set ft=eselect :
diff --git a/libs/tests.bash.in b/libs/tests.bash.in
index e7d5d20..4d32e52 100644
--- a/libs/tests.bash.in
+++ b/libs/tests.bash.in
@@ -1,6 +1,5 @@
#!/bin/bash
-
-# Copyright (c) 2005-2009 Gentoo Foundation.
+# Copyright (c) 2005-2009 Gentoo Foundation -*-eselect-*-
# $Id$
# This file is part of the 'eselect' tools framework.
#
@@ -19,29 +18,24 @@
# has test list
# Return true if list contains test
has() {
- local test=${1} item
- shift
- for item in "$@" ; do
- [[ ${item} == ${test} ]] && return 0
- done
- return 1
+ local test=${1} item
+ shift
+ for item in "$@" ; do
+ [[ ${item} == ${test} ]] && return 0
+ done
+ return 1
}
# is_function function PUBLIC
# Test whether function exists
is_function() {
- [[ $(type -t "${1}" ) == "function" ]]
+ [[ $(type -t "${1}" ) == "function" ]]
}
# is_number PUBLIC
# Returns true if and only if $1 is a positive whole number
is_number() {
- [[ -n ${1} ]] && [[ -z ${1//[[:digit:]]} ]]
+ [[ -n ${1} ]] && [[ -z ${1//[[:digit:]]} ]]
}
-# Local Variables:
-# sh-indentation: 4
-# indent-tabs-mode: nil
-# End:
-
-# vim: set sw=4 et sts=4 tw=80 :
+# vim: set ft=eselect :
diff --git a/modules/config.eselect b/modules/config.eselect
index f9bd72a..9c81df3 100644
--- a/modules/config.eselect
+++ b/modules/config.eselect
@@ -433,4 +433,3 @@ do_interactive() {
}
# vim: set ft=eselect :
-
diff --git a/modules/esd.eselect b/modules/esd.eselect
index 3763b95..5a9fa60 100644
--- a/modules/esd.eselect
+++ b/modules/esd.eselect
@@ -151,4 +151,3 @@ do_update() {
}
# vim: set ft=eselect :
-
diff --git a/modules/timidity.eselect b/modules/timidity.eselect
index e004d40..2220c26 100644
--- a/modules/timidity.eselect
+++ b/modules/timidity.eselect
@@ -23,7 +23,7 @@ find_targets() {
}
destination() {
- if [[ ${global} == "yes" ]]; then
+ if [[ ${global} == "yes" ]]; then
echo "${TIMIDITYDIR}/current"
else
# Ensure the presence of ~/.timidity
@@ -198,4 +198,3 @@ do_update() {
}
# vim: set ft=eselect :
-
diff --git a/modules/vi.eselect b/modules/vi.eselect
index daee369..95e1794 100644
--- a/modules/vi.eselect
+++ b/modules/vi.eselect
@@ -190,4 +190,3 @@ do_update() {
}
# vim: set ft=eselect :
-