diff options
Diffstat (limited to 'gbpm.sh')
| -rwxr-xr-x | gbpm.sh | 34 |
1 files changed, 18 insertions, 16 deletions
@@ -11,7 +11,10 @@ GBPM_VERSION='0.4' -: ${GBPM_OPTS_PATH:="${HOME}/.pythons"} +: ${GBPM_CMD:='gbpm'} +: ${GBPM_LABEL:='version'} +: ${GBPM_LABEL_PL:="${GBPM_LABEL}s"} +: ${GBPM_PATH:="${HOME}/.pythons"} _echo() { echo "echo '${@//\'/\'\\\'\'}'" @@ -23,7 +26,7 @@ _export() { } _warn() { - echo "echo 'gbpm: ${@//\'/\'\\\'\'}' >&2" + echo "echo '${GBPM_CMD}: ${@//\'/\'\\\'\'}' >&2" } _die() { @@ -34,13 +37,12 @@ _die() { } _populate_dirs() { - [[ -d "${GBPM_OPTS_PATH}" ]] \ - || _die "directory ${GBPM_OPTS_PATH} does not exist" + [[ -d "${GBPM_PATH}" ]] || _die "directory ${GBPM_PATH} does not exist" mapfile -td $'\0' dirs < <(shopt -s nullglob; - printf '%s\0' "${GBPM_OPTS_PATH}"/* | sort -zV) + printf '%s\0' "${GBPM_PATH}/"* | sort -zV) - [[ -n "${dirs}" ]] || _die "directory ${GBPM_OPTS_PATH} is empty" + [[ -n "${dirs}" ]] || _die "directory ${GBPM_PATH} is empty" } _populate_selected() { @@ -50,7 +52,7 @@ _populate_selected() { selected=() for dir in "${dirs[@]}"; do - if [[ "${dir}" == "${GBPM_OPTS_PATH}/"* ]]; then + if [[ "${dir}" == "${GBPM_PATH}/"* ]]; then dir="${dir%/bin}" selected+=("${dir##*/}") fi @@ -67,7 +69,7 @@ _clear() { mapfile -td : dirs < <(printf %s "${PATH}") for dir in "${dirs[@]}"; do - if [[ "${dir}" == "${GBPM_OPTS_PATH}/"* ]]; then + if [[ "${dir}" == "${GBPM_PATH}/"* ]]; then _echo "removing ${dir} from PATH" else cdirs+=("${dir}") @@ -142,7 +144,7 @@ cmd_set() { match_pri="${pri}" done - [[ -n "${match}" ]] || _die 'no matching version found' + [[ -n "${match}" ]] || _die "no matching ${GBPM_LABEL} found" _clear _add "${match}" @@ -155,18 +157,18 @@ cmd_clear() { } cmd_version() { - _echo "gbpm ${GBPM_VERSION}" + _echo "${GBPM_CMD} ${GBPM_VERSION}" } cmd_help() { - _echo 'Usage: gbpm <command> [args]' + _echo "Usage: ${GBPM_CMD} <command> [args]" _echo _echo 'Commands:' - _echo ' ls List all available versions' - _echo ' get Display currently selected version' - _echo ' set Select specified version' - _echo ' clear Unselect any selected versions' - _echo ' version Display gbpm version' + _echo " ls List available ${GBPM_LABEL_PL}" + _echo " get Print currently selected ${GBPM_LABEL}" + _echo " set Select specified ${GBPM_LABEL}" + _echo " clear Clear any selected ${GBPM_LABEL_PL}" + _echo " version Print ${GBPM_CMD} version" } case "${1}" in |
