Skip to content

Commit

Permalink
display_path
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Apr 29, 2024
1 parent 9ebd590 commit dbaa7a3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions libexec/rbenv-init
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ if [ -n "$RBENV_ORIG_PATH" ]; then
fi

if [ -z "$print" ]; then
display_path() {
if [ "${1/#$HOME\/}" != "$1" ]; then
# shellcheck disable=SC2088
printf '~/%s' "${1/#$HOME\/}"
else
printf '%s' "$1"
fi
}

rbenv_command=rbenv
if [ -z "$rbenv_in_path" ]; then
rbenv_command="$root/bin/rbenv"
rbenv_command="${rbenv_command/$HOME\//\~/}"
rbenv_command="$(display_path "$root/bin/rbenv")"
fi

color_start=""
Expand All @@ -81,13 +89,13 @@ if [ -z "$print" ]; then

write_config() {
if grep -q "rbenv init" "$1" 2>/dev/null; then
printf 'skipping %s%s%s: already configured for rbenv.\n' "$color_start" "${1/$HOME\//\~/}" "$color_end"
printf 'skipping %s%s%s: already configured for rbenv.\n' "$color_start" "$(display_path "$1")" "$color_end"
return 0
fi
mkdir -p "${1%/*}"
# shellcheck disable=SC2016
printf '\n# Added by `rbenv init` on %s\n%s\n' "$(date)" "$2" >> "$1"
printf 'writing %s%s%s: now configured for rbenv.\n' "$color_start" "${1/$HOME\//\~/}" "$color_end"
printf 'writing %s%s%s: now configured for rbenv.\n' "$color_start" "$(display_path "$1")" "$color_end"
}

status=0
Expand Down

0 comments on commit dbaa7a3

Please sign in to comment.