aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README9
-rwxr-xr-xgbpm.sh34
2 files changed, 25 insertions, 18 deletions
diff --git a/README b/README
index 36cc9fd..6f2c715 100644
--- a/README
+++ b/README
@@ -29,13 +29,18 @@ INSTALLING
pypm() {
. <(
- GBPM_OPTS_PATH="${HOME}/.pythons" \
+ GBPM_CMD='pypm' \
+ GBPM_LABEL='python' \
+ GBPM_PATH="${HOME}/.pythons" \
/path/to/gbpm.sh "${@}")
}
rbpm() {
. <(
- GBPM_OPTS_PATH="${HOME}/.rubies" \
+ GBPM_CMD='rbpm' \
+ GBPM_LABEL='ruby' \
+ GBPM_LABEL_PL='rubies' \
+ GBPM_PATH="${HOME}/.rubies" \
/path/to/gbpm.sh "${@}")
}
diff --git a/gbpm.sh b/gbpm.sh
index e96ce69..9518fba 100755
--- a/gbpm.sh
+++ b/gbpm.sh
@@ -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