--- sh.eselect-0.1 2009-09-06 15:32:57.000000000 +0200 +++ sh.eselect-0.1 2009-09-20 10:58:26.702457192 +0200 @@ -4,7 +4,7 @@ DESCRIPTION="Manage /bin/sh (POSIX shell) implementations" MAINTAINER="gentoo@mgorny.alt.pl" -VERSION="0.1" +VERSION="0.2_rc" # Based on work of Erik Hahn; bug #214817 @@ -19,7 +19,7 @@ find_targets() { zsh \ posh \ ; do - if [[ -x "${ROOT}"/bin/${t} ]]; then + if [[ -x ${ROOT}/bin/${t} ]]; then echo ${t} fi done @@ -29,15 +29,15 @@ find_targets() { set_symlinks() { local target="${1}" targets - [[ ! -L "${ROOT}"/bin/sh && -e "${ROOT}"/bin/sh ]] && \ + [[ ! -L ${ROOT}/bin/sh && -e ${ROOT}/bin/sh ]] && \ die -q "/bin/sh is not a symlink!" if is_number "${target}" && [[ ${target} -ge 1 ]]; then targets=( $(find_targets) ) - target=${targets[$(( ${target} - 1 ))]} + target=${targets[target-1]} fi - if [[ -x "${ROOT}"/bin/${target} ]]; then + if [[ -x ${ROOT}/bin/${target} ]]; then local tmpf="${ROOT}"/bin/sh.new # we could use 'ln -f' to directly replace the symlink # but 'mv' is an atomic operation so it should be more fault-proof @@ -60,12 +60,12 @@ describe_show() { } do_show() { - [[ -z "${@}" ]] || die -q "Too many parameters" + [[ -z ${@} ]] || die -q "Too many parameters" write_list_start "Current POSIX shell implementation:" - if [[ -L "${ROOT}/bin/sh" ]]; then - write_kv_list_entry "$(basename $(canonicalise ${ROOT}/bin/sh))" "" - elif [[ -e "${ROOT}/bin/sh" ]]; then + if [[ -L ${ROOT}/bin/sh ]]; then + write_kv_list_entry "$(basename $(readlink ${ROOT}/bin/sh))" "" + elif [[ -e ${ROOT}/bin/sh ]]; then write_kv_list_entry "(not a symlink)" "" else write_kv_list_entry "(unset)" "" @@ -79,13 +79,13 @@ describe_list() { } do_list() { - [[ -z "${@}" ]] || die -q "Too many parameters" + [[ -z ${@} ]] || die -q "Too many parameters" local i targets targets=( $(find_targets) ) if [[ -n ${targets[@]} ]]; then for (( i = 0; i < ${#targets[@]}; i++ )) ; do - [[ ${targets[${i}]} == $(basename $(canonicalise ${ROOT}/bin/sh)) ]] && \ + [[ ${targets[${i}]} == $(basename $(readlink ${ROOT}/bin/sh)) ]] && \ targets[${i}]="${targets[${i}]} $(highlight '*')" done write_list_start "Available POSIX shell implementations:" @@ -110,9 +110,9 @@ describe_set_parameters() { } do_set() { - if [[ -z "${1}" ]]; then + if [[ -z ${1} ]]; then die -q "Not enough parameters" - elif [[ -n "${2}" ]]; then + elif [[ -n ${2} ]]; then die -q "Too many parameters" else set_symlinks "${1}" @@ -126,14 +126,14 @@ describe_update() { } describe_update_options() { - echo "--if-unset : Do not override existing implementation" + echo "ifunset : Do not override existing implementation" } do_update() { - [[ -z "${1}" || ( -z "${2}" && "${1}" == "--if-unset" ) ]] || \ + [[ -z ${1} || ( -z ${2} && ( ${1} == ifunset || ${1} == '--if-unset' ) ]] || \ die -q "Usage error" - [[ "${1}" == "--if-unset" && -L "${ROOT}"/bin/sh && -x "${ROOT}"/bin/sh ]] && \ + [[ ( ${1} == ifunset || ${1} == '--if-unset' ) && -L ${ROOT}/bin/sh && -x ${ROOT}/bin/sh ]] && \ return set_symlinks 1