Your IP : 216.73.216.21


Current Path : /pkg/perl/.plenv/libexec/
Upload File :
Current File : //pkg/perl/.plenv/libexec/plenv-rehash

#!/usr/bin/env bash
# Summary: Rehash plenv shims (run this after installing executables)

set -e
[ -n "$PLENV_DEBUG" ] && set -x

SHIM_PATH="${PLENV_ROOT}/shims"
PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.plenv-shim"

# Create the shims directory if it doesn't already exist.
mkdir -p "$SHIM_PATH"

# Ensure only one instance of plenv-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
# to stderr and exit with a non-zero status.
set -o noclobber
{ echo > "$PROTOTYPE_SHIM_PATH"
} 2>/dev/null ||
{ if [ -w "$SHIM_PATH" ]; then
    echo "plenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists"
  else
    echo "plenv: cannot rehash: $SHIM_PATH isn't writable"
  fi
  exit 1
} >&2
set +o noclobber

# If we were able to obtain a lock, register a trap to clean up the
# prototype shim when the process exits.
trap remove_prototype_shim EXIT

remove_prototype_shim() {
  command -p rm -f "$PROTOTYPE_SHIM_PATH"
}

# The prototype shim file is a script that re-execs itself, passing
# its filename and any arguments to `plenv exec`. This file is
# hard-linked for every executable and then removed. The linking
# technique is fast, uses less disk space than unique files, and also
# serves as a locking mechanism.
create_prototype_shim() {
  command -p cat > "$PROTOTYPE_SHIM_PATH" <<SH
#!$(command -v bash)
[[ -n "\$PLENV_DEBUG" ]] && set -x
PLENV_ROOT='$PLENV_ROOT' exec '$(command -v plenv)' exec "\${0##*/}" "\$@"
SH
  command -p chmod +x "$PROTOTYPE_SHIM_PATH"
}

# If the contents of the prototype shim file differ from the contents
# of the first shim in the shims directory, assume plenv has been
# upgraded and the existing shims need to be removed.
remove_outdated_shims() {
  for shim in *; do
    if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then
      for shim in *; do command -p rm -f "$shim"; done
    fi
    break
  done
}

# The basename of each argument passed to `make_shims` will be
# registered for installation as a shim. In this way, plugins may call
# `make_shims` with a glob to register many shims at once.
make_shims() {
  local shims="$@"

  for file in $shims; do
    local shim="${file##*/}"
    register_shim "$shim"
  done
}

# Create an empty array for the list of registered shims and an empty
# string to use as a search index.
registered_shims=()
registered_shims_index=""

# We will keep track of shims registered for installation with the
# global `registered_shims` array and with a global search index
# string. The array will let us iterate over all registered shims. The
# index string will let us quickly check whether a shim with the given
# name has been registered or not.
register_shim() {
  local shim="$@"
  registered_shims["${#registered_shims[@]}"]="$shim"
  registered_shims_index="$registered_shims_index/$shim/"
}

# To install all the registered shims, we iterate over the
# `registered_shims` array and create a link if one does not already
# exist.
install_registered_shims() {
  local shim
  for shim in "${registered_shims[@]}"; do
    [ -e "$shim" ] || command -p ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
  done
}

# Once the registered shims have been installed, we make a second pass
# over the contents of the shims directory. Any file that is present
# in the directory but has not been registered as a shim should be
# removed.
remove_stale_shims() {
  local shim
  for shim in *; do
    if [[ "$registered_shims_index" != *"/$shim/"* ]]; then
      command -p rm -f "$shim"
    fi
  done
}


# Change to the shims directory.
cd "$SHIM_PATH"
shopt -s nullglob

# Create the prototype shim, then register shims for all known
# executables.
create_prototype_shim
remove_outdated_shims
make_shims ../versions/*/bin/*

# Restore the previous working directory.
cd "$OLDPWD"

# Allow plugins to register shims.
OLDIFS="$IFS"
IFS=$'\n' scripts=(`plenv-hooks rehash`)
IFS="$OLDIFS"

for script in "${scripts[@]}"; do
  source "$script"
done

# Change back to the shims directory to install the registered shims
# and remove stale shims.
cd "$SHIM_PATH"
install_registered_shims
remove_stale_shims

https://nalibali.org/post-sitemap.xml 2026-11-20T09:00:00+00:00 https://nalibali.org/page-sitemap.xml 2026-11-18T09:24:11+00:00 https://nalibali.org/stories-sitemap.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/stories-sitemap2.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/audio_stories-sitemap.xml 2026-03-27T06:53:13+00:00 https://nalibali.org/story_cards-sitemap.xml 2025-06-06T10:27:48+00:00 https://nalibali.org/story_seeds-sitemap.xml 2025-05-19T07:35:43+00:00 https://nalibali.org/rhymes-sitemap.xml 2025-06-17T07:43:10+00:00 https://nalibali.org/activity_sheets-sitemap.xml 2025-05-16T09:16:43+00:00 https://nalibali.org/printables-sitemap.xml 2025-05-16T09:28:40+00:00 https://nalibali.org/posters_bookmarks-sitemap.xml 2025-05-16T10:20:22+00:00 https://nalibali.org/team_member-sitemap.xml 2025-05-28T09:40:43+00:00 https://nalibali.org/video_stories-sitemap.xml 2025-06-23T08:48:28+00:00 https://nalibali.org/guides-sitemap.xml 2025-06-17T09:38:41+00:00 https://nalibali.org/story_supplements-sitemap.xml 2025-09-16T12:22:20+00:00 https://nalibali.org/vacancies-sitemap.xml 2026-09-17T07:05:01+00:00 https://nalibali.org/category-sitemap.xml 2026-11-20T09:00:00+00:00 https://nalibali.org/post_tag-sitemap.xml 2026-11-06T00:00:00+00:00 https://nalibali.org/test-sitemap.xml 2025-06-13T09:36:28+00:00 https://nalibali.org/story_categories-sitemap.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/activity_sheets_categories-sitemap.xml 2025-05-16T09:16:43+00:00 https://nalibali.org/printables_categories-sitemap.xml 2025-05-16T09:28:40+00:00 https://nalibali.org/posters_bookmarks_categories-sitemap.xml 2025-05-16T10:20:22+00:00 https://nalibali.org/single_audio-sitemap.xml 2026-03-27T06:53:13+00:00 https://nalibali.org/rhyme_categories-sitemap.xml 2025-06-17T07:43:10+00:00 https://nalibali.org/guide_categories-sitemap.xml 2025-06-17T09:38:41+00:00 https://nalibali.org/author-sitemap.xml 2026-01-22T07:26:07+00:00