Browse Source

fix: allow a --force option on rehash to remove .jenv-shim

pull/462/head
andrewflbarnes 2 weeks ago
parent
commit
770c0d6fbc
No known key found for this signature in database
  1. 21
      libexec/jenv-rehash
  2. 2
      libexec/jenv-sh-rehash

21
libexec/jenv-rehash

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
#!/usr/bin/env bash
# Summary: Rehash jenv shims (run this after installing executables)
# Provide jenv completions
if [ "$1" = "--complete" ]; then
echo --force
exit
fi
set -e
[ -n "$JENV_DEBUG" ] && set -x
@ -11,6 +16,14 @@ PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.jenv-shim" @@ -11,6 +16,14 @@ PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.jenv-shim"
# Create the shims directory if it doesn't already exist.
mkdir -p "$SHIM_PATH"
remove_prototype_shim() {
rm -f "$PROTOTYPE_SHIM_PATH"
}
if [ "$1" = "--force" ]; then
remove_prototype_shim
fi
# Ensure only one instance of jenv-rehash is running at a time by
# setting the shell's `noclobber` option and attempting to write to
# the prototype shim file. If the file already exists, print a warning
@ -18,7 +31,7 @@ mkdir -p "$SHIM_PATH" @@ -18,7 +31,7 @@ mkdir -p "$SHIM_PATH"
set -o noclobber
{ echo > "$PROTOTYPE_SHIM_PATH"
} 2>/dev/null ||
{ echo "jenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
{ echo "jenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists, try 'jenv rehash --force' to override"
exit 1
} >&2
set +o noclobber
@ -27,10 +40,6 @@ set +o noclobber @@ -27,10 +40,6 @@ set +o noclobber
# prototype shim when the process exits.
trap remove_prototype_shim EXIT
remove_prototype_shim() {
rm -f "$PROTOTYPE_SHIM_PATH"
}
remove_from_path() {
local path_to_remove="$(expand_path "$1")"
local result=""

2
libexec/jenv-sh-rehash

@ -9,7 +9,7 @@ fi @@ -9,7 +9,7 @@ fi
# When jenv shell integration is enabled, delegate to jenv-rehash,
# then tell the shell to empty its command lookup cache.
jenv-rehash
jenv-rehash "$@"
case "$shell" in
fish )

Loading…
Cancel
Save