Comments (10)
I guess you either hardcode the path to head or cat (i.e. /usr/bin/head or /bin/cat) but that would make things a bit less portable. You can alternatively choose to blacklist head, cat commands from symlinking in shims, since putting them in the PATH makes no sense.
PPT's bin commands are fun experiments to reimplement UNIX commands in perl, but putting them in $PATH asks for problems.
from plenv.
Hmmm... I understand the problem, but I don't have a good idea to resolve
this issue.
On Fri, Feb 27, 2015 at 6:54 AM Tatsuhiko Miyagawa [email protected]
wrote:
I guess you either hardcode the path to head or cat (i.e. /usr/bin/head or
/bin/cat) but that would make things a bit less portable. You can
alternatively choose to blacklist head, cat commands from symlinking in
shims, since putting them in the PATH makes no sense.PPT's bin commands are fun experiments to reimplement UNIX commands in
perl, but putting them in $PATH asks for problems.—
Reply to this email directly or view it on GitHub
#78 (comment).
from plenv.
from plenv.
Another solution is to write cat/head in pure bash. I'm no bash expert but it doesn't seem that hard.
from plenv.
read
which is a bash builtin function can be used instead of both head
and cat
like following the patch. However it is difficult(impossible?) to replace with chmod with bash functions.
diff --git a/libexec/plenv b/libexec/plenv
index a165f4b..a648499 100755
--- a/libexec/plenv
+++ b/libexec/plenv
@@ -12,7 +12,7 @@ if [ -n "$PLENV_DEBUG" ]; then
set -x
fi
-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | while read line; do echo -n $line; break; done)
if [ -z "$READLINK" ]; then
echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
diff --git a/libexec/plenv-hooks b/libexec/plenv-hooks
index 3b3f7d8..64d37b0 100755
--- a/libexec/plenv-hooks
+++ b/libexec/plenv-hooks
@@ -19,7 +19,7 @@ if [ -z "$PLENV_COMMAND" ]; then
exit 1
fi
-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | while read line; do echo -n $line; break; done)
if [ -z "$READLINK" ]; then
echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
diff --git a/libexec/plenv-init b/libexec/plenv-init
index d90ea07..915b0b8 100755
--- a/libexec/plenv-init
+++ b/libexec/plenv-init
@@ -27,7 +27,7 @@ if [ -z "$shell" ]; then
shell="$(basename "${shell:-$SHELL}")"
fi
-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | while line; do echo -n $line; break; done)
if [ -z "$READLINK" ]; then
echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
diff --git a/libexec/plenv-rehash b/libexec/plenv-rehash
index 31b8b47..52e1a6f 100755
--- a/libexec/plenv-rehash
+++ b/libexec/plenv-rehash
@@ -40,7 +40,7 @@ remove_prototype_shim() {
# technique is fast, uses less disk space than unique files, and also
# serves as a locking mechanism.
create_prototype_shim() {
- cat > "$PROTOTYPE_SHIM_PATH" <<SH
+ $(read -r -d '' shim <<SH
#!/usr/bin/env bash
set -e
[ -n "\$PLENV_DEBUG" ] && set -x
@@ -59,6 +59,7 @@ fi
export PLENV_ROOT="$PLENV_ROOT"
exec "$(command -v plenv)" exec "\$program" "\$@"
SH
+echo "$shim" > "$PROTOTYPE_SHIM_PATH")
chmod +x "$PROTOTYPE_SHIM_PATH"
}
bash is difficult :-(
- http://labs.timedia.co.jp/2011/09/shell-read-pipe-and-environment-variables.html
- http://stackoverflow.com/questions/1167746/how-to-assign-a-heredoc-value-to-a-variable-in-bash
from plenv.
I can install PerlPowerTools
with following patch(gist).
diff --git a/libexec/plenv b/libexec/plenv
index a165f4b..8b3c47e 100755
--- a/libexec/plenv
+++ b/libexec/plenv
@@ -12,12 +12,25 @@ if [ -n "$PLENV_DEBUG" ]; then
set -x
fi
-READLINK=$(type -p greadlink readlink | head -1)
+head1() {
+ while read line do
+ do
+ echo $line
+ break;
+ done
+}
+
+READLINK=$(type -p greadlink readlink | head1)
if [ -z "$READLINK" ]; then
echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi
+export PLENV_CMD_CAT=$(type -p /bin/cat /usr/bin/cat | head1)
+export PLENV_CMD_LN=$(type -p /bin/ln /usr/bin/ln | head1)
+export PLENV_CMD_CHMOD=$(type -p /bin/chmod /usr/bin/chmod | head1)
+export PLENV_CMD_RM=$(type -p /bin/rm /usr/bin/rm | head1)
+
resolve_link() {
$READLINK "$1"
}
diff --git a/libexec/plenv-hooks b/libexec/plenv-hooks
index 3b3f7d8..61d2e80 100755
--- a/libexec/plenv-hooks
+++ b/libexec/plenv-hooks
@@ -19,7 +19,7 @@ if [ -z "$PLENV_COMMAND" ]; then
exit 1
fi
-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | while read line; do echo $line; break; done)
if [ -z "$READLINK" ]; then
echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
diff --git a/libexec/plenv-init b/libexec/plenv-init
index 8bbf0b7..8c3856d 100755
--- a/libexec/plenv-init
+++ b/libexec/plenv-init
@@ -27,7 +27,7 @@ if [ -z "$shell" ]; then
shell="$(basename "${shell:-$SHELL}")"
fi
-READLINK=$(type -p greadlink readlink | head -1)
+READLINK=$(type -p greadlink readlink | while read line; do echo $line; break; done)
if [ -z "$READLINK" ]; then
echo "plenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
@@ -119,7 +119,7 @@ fi
commands=(`plenv-commands --sh`)
case "$shell" in
fish )
- cat <<EOS
+ $PLENV_CMD_CAT <<EOS
function plenv
set command \$argv[1]
set -e argv[1]
@@ -134,7 +134,7 @@ end
EOS
;;
ksh )
- cat <<EOS
+ $PLENV_CMD_CAT <<EOS
function plenv {
typeset command
EOS
@@ -149,7 +149,7 @@ esac
if [ "$shell" != "fish" ]; then
IFS="|"
-cat <<EOS
+$PLENV_CMD_CAT <<EOS
command="\$1"
if [ "\$#" -gt 0 ]; then
shift
diff --git a/libexec/plenv-local b/libexec/plenv-local
index c2ae93f..b3b2b44 100755
--- a/libexec/plenv-local
+++ b/libexec/plenv-local
@@ -36,12 +36,12 @@ fi
PLENV_VERSION="$1"
if [ "$PLENV_VERSION" = "--unset" ]; then
- rm -f .perl-version .plenv-version
+ $PLENV_CMD_RM -f .perl-version .plenv-version
elif [ -n "$PLENV_VERSION" ]; then
previous_file="$(PLENV_VERSION= plenv-version-origin || true)"
plenv-version-file-write .perl-version "$PLENV_VERSION"
if [ "$previous_file" -ef .plenv-version ]; then
- rm -f .plenv-version
+ $PLENV_CMD_RM -f .plenv-version
{ echo "plenv: removed existing \`.plenv-version' file and migrated"
echo " local version specification to \`.perl-version' file"
} >&2
diff --git a/libexec/plenv-rehash b/libexec/plenv-rehash
index 31b8b47..13c976c 100755
--- a/libexec/plenv-rehash
+++ b/libexec/plenv-rehash
@@ -31,7 +31,7 @@ set +o noclobber
trap remove_prototype_shim EXIT
remove_prototype_shim() {
- rm -f "$PROTOTYPE_SHIM_PATH"
+ $PLENV_CMD_RM -f "$PROTOTYPE_SHIM_PATH"
}
# The prototype shim file is a script that re-execs itself, passing
@@ -40,7 +40,7 @@ remove_prototype_shim() {
# technique is fast, uses less disk space than unique files, and also
# serves as a locking mechanism.
create_prototype_shim() {
- cat > "$PROTOTYPE_SHIM_PATH" <<SH
+ $PLENV_CMD_CAT > "$PROTOTYPE_SHIM_PATH" <<SH
#!/usr/bin/env bash
set -e
[ -n "\$PLENV_DEBUG" ] && set -x
@@ -59,7 +59,7 @@ fi
export PLENV_ROOT="$PLENV_ROOT"
exec "$(command -v plenv)" exec "\$program" "\$@"
SH
- chmod +x "$PROTOTYPE_SHIM_PATH"
+ $PLENV_CMD_CHMOD +x "$PROTOTYPE_SHIM_PATH"
}
# If the contents of the prototype shim file differ from the contents
@@ -68,7 +68,7 @@ SH
remove_outdated_shims() {
for shim in *; do
if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then
- for shim in *; do rm -f "$shim"; done
+ for shim in *; do $PLENV_CMD_RM -f "$shim"; done
fi
break
done
@@ -108,7 +108,7 @@ register_shim() {
install_registered_shims() {
local shim
for shim in "${registered_shims[@]}"; do
- [ -e "$shim" ] || ln -f "$PROTOTYPE_SHIM_PATH" "$shim"
+ [ -e "$shim" ] || $PLENV_CMD_LN -f "$PROTOTYPE_SHIM_PATH" "$shim"
done
}
@@ -120,7 +120,7 @@ remove_stale_shims() {
local shim
for shim in *; do
if [[ "$registered_shims_index" != *"/$shim/"* ]]; then
- rm -f "$shim"
+ $PLENV_CMD_RM -f "$shim"
fi
done
}
diff --git a/libexec/plenv-version-file-read b/libexec/plenv-version-file-read
index 976924c..97fd97b 100755
--- a/libexec/plenv-version-file-read
+++ b/libexec/plenv-version-file-read
@@ -14,7 +14,7 @@ if [ -e "$VERSION_FILE" ]; then
if [ -z "$version" ] && [ -n "$word" ]; then
version="$word"
fi
- done < <( cat "$VERSION_FILE" && echo )
+ done < <( $PLENV_CMD_CAT "$VERSION_FILE" && echo )
if [ -n "$version" ]; then
echo "$version"
diff --git a/plenv.d/rehash/rehash_cpanm.bash b/plenv.d/rehash/rehash_cpanm.bash
index 740eadd..901adaf 100755
--- a/plenv.d/rehash/rehash_cpanm.bash
+++ b/plenv.d/rehash/rehash_cpanm.bash
@@ -25,4 +25,4 @@ done
exit \$rc
SH
-chmod +x "$CPANM_SHIM_PATH"
+$PLENV_CMD_CHMOD +x "$CPANM_SHIM_PATH"
NOTE How to clean up
Installing PerlPowerTools
is dangerous . Many tools(cpanm
etc) cannot work after install
PerlPowerTools
.
- Remove
shims
directory(rm -rf ~/.plenv/shims
) - Uninstalling
PerlPowerTools
(~/.plenv/versions/your_perl_version/bin/cpanm --uninstall PerlPowerTools
) - Re-generate symbolic links(
plenv rehash
)
from plenv.
@syohex the patch looks good to me!
I agree about the dangerous aspect of PPT, was wondering if I should make a PR on there to stop installing these executables by default.
from plenv.
@miyagawa Thanks for reviewing. I have sent PR #79.
from plenv.
Is this something because the PerlPowerTools version of head needs to be fixed to work like the real head you were expecting or because plenv gets confused because any file of that name (no matter what it does) will cause it to be confused?
I'll make a change to PerlPowerTools to not install into perl's bin, but this seems to be a fundamental flaw in plenv. I've done similar things locally with my own tools and run into this problem. This means even though I change PerlPowerTools, you still have this problem if someone does something similar. For instance, LWP used to install a "head", as I recall.
from plenv.
@briandfoy yes it's fixed in #79
from plenv.
Related Issues (20)
- "man perl" shows system Perl manual under local Perl dir (.perl-version) HOT 3
- homebrew plenv v2.3.0 is claiming it is 2.2.0 HOT 1
- Homebrew shows incorrect plenv versioning HOT 1
- no backend configured for scheme https HOT 7
- Plenv to control additional Perl lib paths (PERL5LIB env var?) HOT 7
- Complain about active local::lib in ~/perl5
- plenv install fails with "newer" Perls HOT 3
- failure when attempting to install any Perl version on macOS Big Sur HOT 8
- Separate GitHub Organization for plenv
- Use plenv-rehash to install the hooks from plugins
- How to use with wayland? HOT 2
- Respect .perl-version through symlinks?
- No problem to install-cpanm, but failed to find cpanm command HOT 6
- Thank you - seems to work in ksh93 HOT 1
- plenv should update MANPATH so that man pages installed in a plenv-managed Perl are found HOT 5
- install-cpanm Fails: ERROR: Cannot find the tarball for perl-cpanm HOT 2
- mxcl. in link
- plenv: no such command `shell'
- To support environments except bash/zsh( such as csh)
- `plenv migrate-modules` may break List::Util(and cpanm)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plenv.