From 52d6acc3b05e2981da724319f511ec57882809ac Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Thu, 20 Jul 2017 01:25:12 +0000 Subject: [PATCH 1/4] Workaround for scripts in `$PATH` which needs to be source'd (#100, #688) --- pyenv.d/rehash/source.bash | 30 ++++++++++++++++++++++++++++++ pyenv.d/rehash/source.txt | 1 + 2 files changed, 31 insertions(+) create mode 100644 pyenv.d/rehash/source.bash create mode 100644 pyenv.d/rehash/source.txt diff --git a/pyenv.d/rehash/source.bash b/pyenv.d/rehash/source.bash new file mode 100644 index 00000000..c4f73da8 --- /dev/null +++ b/pyenv.d/rehash/source.bash @@ -0,0 +1,30 @@ +PROTOTYPE_SOURCE_SHIM_PATH="${SHIM_PATH}/.pyenv-source-shim" + +shims=() +for shim in $(cat "${BASH_SOURCE%/*}/source.txt"); do + if [ -n "${shim%%#*}" ]; then + shims[${#shims[*]}]="${shim})return 0;;" + fi +done +eval "source_shim(){ case \"\$1\" in ${shims[@]} *)return 1;;esac;}" + +cat > "${PROTOTYPE_SOURCE_SHIM_PATH}" < Date: Fri, 21 Jul 2017 00:43:23 +0000 Subject: [PATCH 2/4] Move `conda.txt` and `source.txt` into their directory to allow users to have custom blacklist --- pyenv.d/rehash/conda.bash | 6 ++++-- pyenv.d/rehash/conda.d/.gitignore | 3 +++ pyenv.d/rehash/{conda.txt => conda.d/default.list} | 0 pyenv.d/rehash/source.bash | 6 ++++-- pyenv.d/rehash/source.d/.gitignore | 3 +++ pyenv.d/rehash/source.d/default.list | 6 ++++++ pyenv.d/rehash/source.txt | 1 - 7 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 pyenv.d/rehash/conda.d/.gitignore rename pyenv.d/rehash/{conda.txt => conda.d/default.list} (100%) create mode 100644 pyenv.d/rehash/source.d/.gitignore create mode 100644 pyenv.d/rehash/source.d/default.list delete mode 100644 pyenv.d/rehash/source.txt diff --git a/pyenv.d/rehash/conda.bash b/pyenv.d/rehash/conda.bash index 9b22dfb0..6febe61b 100644 --- a/pyenv.d/rehash/conda.bash +++ b/pyenv.d/rehash/conda.bash @@ -12,11 +12,13 @@ conda_exists() { } shims=() -for shim in $(cat "${BASH_SOURCE%/*}/conda.txt"); do - if [ -n "${shim%%#*}" ]; then +shopt -s nullglob +for shim in $(cat "${BASH_SOURCE%/*}/conda.d/"*".list" | sort | uniq | sed -e 's/#.*$//' | sed -e '/^[[:space:]]*$/d'); do + if [ -n "${shim##*/}" ]; then shims[${#shims[*]}]="${shim})return 0;;" fi done +shopt -u nullglob eval "conda_shim(){ case \"\$1\" in ${shims[@]} *)return 1;;esac;}" # override `make_shims` to avoid conflict between pyenv-virtualenv's `envs.bash` diff --git a/pyenv.d/rehash/conda.d/.gitignore b/pyenv.d/rehash/conda.d/.gitignore new file mode 100644 index 00000000..655d89c2 --- /dev/null +++ b/pyenv.d/rehash/conda.d/.gitignore @@ -0,0 +1,3 @@ +* +!/.gitignore +!/default.list diff --git a/pyenv.d/rehash/conda.txt b/pyenv.d/rehash/conda.d/default.list similarity index 100% rename from pyenv.d/rehash/conda.txt rename to pyenv.d/rehash/conda.d/default.list diff --git a/pyenv.d/rehash/source.bash b/pyenv.d/rehash/source.bash index c4f73da8..f9e02ee3 100644 --- a/pyenv.d/rehash/source.bash +++ b/pyenv.d/rehash/source.bash @@ -1,11 +1,13 @@ PROTOTYPE_SOURCE_SHIM_PATH="${SHIM_PATH}/.pyenv-source-shim" shims=() -for shim in $(cat "${BASH_SOURCE%/*}/source.txt"); do - if [ -n "${shim%%#*}" ]; then +shopt -s nullglob +for shim in $(cat "${BASH_SOURCE%/*}/source.d/"*".list" | sort | uniq | sed -e 's/#.*$//' | sed -e '/^[[:space:]]*$/d'); do + if [ -n "${shim##*/}" ]; then shims[${#shims[*]}]="${shim})return 0;;" fi done +shopt -u nullglob eval "source_shim(){ case \"\$1\" in ${shims[@]} *)return 1;;esac;}" cat > "${PROTOTYPE_SOURCE_SHIM_PATH}" < Date: Fri, 21 Jul 2017 00:55:11 +0000 Subject: [PATCH 3/4] I should have used basename only to check shims --- pyenv.d/rehash/conda.bash | 2 +- pyenv.d/rehash/source.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyenv.d/rehash/conda.bash b/pyenv.d/rehash/conda.bash index 6febe61b..a45a9966 100644 --- a/pyenv.d/rehash/conda.bash +++ b/pyenv.d/rehash/conda.bash @@ -19,7 +19,7 @@ for shim in $(cat "${BASH_SOURCE%/*}/conda.d/"*".list" | sort | uniq | sed -e 's fi done shopt -u nullglob -eval "conda_shim(){ case \"\$1\" in ${shims[@]} *)return 1;;esac;}" +eval "conda_shim(){ case \"\${1##*/}\" in ${shims[@]} *)return 1;;esac;}" # override `make_shims` to avoid conflict between pyenv-virtualenv's `envs.bash` # https://github.com/pyenv/pyenv-virtualenv/blob/v20160716/etc/pyenv.d/rehash/envs.bash diff --git a/pyenv.d/rehash/source.bash b/pyenv.d/rehash/source.bash index f9e02ee3..3b329491 100644 --- a/pyenv.d/rehash/source.bash +++ b/pyenv.d/rehash/source.bash @@ -8,7 +8,7 @@ for shim in $(cat "${BASH_SOURCE%/*}/source.d/"*".list" | sort | uniq | sed -e ' fi done shopt -u nullglob -eval "source_shim(){ case \"\$1\" in ${shims[@]} *)return 1;;esac;}" +eval "source_shim(){ case \"\${1##*/}\" in ${shims[@]} *)return 1;;esac;}" cat > "${PROTOTYPE_SOURCE_SHIM_PATH}" < Date: Fri, 21 Jul 2017 00:55:37 +0000 Subject: [PATCH 4/4] Stop assuming `bash` for source scripts --- pyenv.d/rehash/source.bash | 1 - 1 file changed, 1 deletion(-) diff --git a/pyenv.d/rehash/source.bash b/pyenv.d/rehash/source.bash index 3b329491..6bcbcbd7 100644 --- a/pyenv.d/rehash/source.bash +++ b/pyenv.d/rehash/source.bash @@ -11,7 +11,6 @@ shopt -u nullglob eval "source_shim(){ case \"\${1##*/}\" in ${shims[@]} *)return 1;;esac;}" cat > "${PROTOTYPE_SOURCE_SHIM_PATH}" <