-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update shell config file during installation (bash & zsh) #137
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,17 @@ if [ -z "$PYENV_ROOT" ]; then | |
export PYENV_ROOT="${HOME}/.pyenv" | ||
fi | ||
|
||
if [ -z "$shell" ]; then | ||
shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)" | ||
shell="${shell%% *}" | ||
shell="${shell##-}" | ||
shell="${shell:-$SHELL}" | ||
shell="${shell##*/}" | ||
shell="${shell%%-*}" | ||
fi | ||
|
||
USER_PATH_ADDED=false | ||
|
||
colorize() { | ||
if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2" | ||
else echo -n "$2" | ||
|
@@ -50,7 +61,57 @@ checkout "${GITHUB}/pyenv/pyenv-update.git" "${PYENV_ROOT}/plugins/pyenv-upd | |
checkout "${GITHUB}/pyenv/pyenv-virtualenv.git" "${PYENV_ROOT}/plugins/pyenv-virtualenv" "master" | ||
checkout "${GITHUB}/pyenv/pyenv-which-ext.git" "${PYENV_ROOT}/plugins/pyenv-which-ext" "master" | ||
|
||
write_source() { | ||
# expand ~ to user's home | ||
local target="${1/#\~/$HOME}" | ||
|
||
echo "Update file: $1" >&2 | ||
|
||
echo "" >>$target | ||
echo '# pyenv' >>$target | ||
echo 'export PATH="'"$PYENV_ROOT/bin:"'$PATH"' >>$target | ||
echo 'eval "$(pyenv init -)"' >>$target | ||
echo 'eval "$(pyenv virtualenv-init -)"' >>$target | ||
|
||
USER_PATH_ADDED=true | ||
} | ||
|
||
Comment on lines
+64
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still heavily dislike the duplication with I understand the desire to keep installation logic out of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "is-Pyenv-shell-setup-already-done" part of the logic is something that could probably be kept out of Pyenv-Init -- if it proves to be different enough from existing Pyenv-Init logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add |
||
add_userpath() { | ||
# Will detect rc files by setting variables below: | ||
# PYENV_SHELL_DETECT | ||
# PYENV_PROFILE_DETECT | ||
# PYENV_RC_DETECT | ||
eval "$(${PYENV_ROOT}/bin/pyenv init --detect-shell $shell)" | ||
|
||
case "$PYENV_SHELL_DETECT" in | ||
bash ) | ||
write_source $PYENV_PROFILE_DETECT | ||
write_source $PYENV_RC_DETECT | ||
;; | ||
zsh ) | ||
write_source $PYENV_PROFILE_DETECT | ||
write_source $PYENV_RC_DETECT | ||
;; | ||
ksh ) | ||
write_source $PYENV_PROFILE_DETECT | ||
;; | ||
* ) | ||
{ | ||
echo "Add userpath for $PYENV_SHELL_DETECT is not currently supported" | ||
echo "Please set up manually" | ||
} >&2 | ||
;; | ||
esac | ||
} | ||
|
||
if ! command -v pyenv 1>/dev/null; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the logic behind this criterion? Maybe rather check that shell config files don't have any mention of "pyenv"? Or run a new shell with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I lost the context of this comment. Could you check if this still being an issue after reviewing the updated code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICS, this line is supposed to detect whether we need to add shell configuration stuff, or if it's already present. I can't see how this test achieves that. Since there's an infinite variety of setups, perhaps the best way of action is to see how other language managers do this -- to see what measures have proven to be sufficient in practice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This criterion is based on assumptions of how
This criterion is not water-proof, especially for users that rerun the installer many times without restarting their shell. But it's probably the simplest way AFAICS. |
||
|
||
add_userpath | ||
if ${USER_PATH_ADDED}; then | ||
echo "Restart your shell to start using pyenv" >&2 | ||
exit 0 | ||
fi | ||
|
||
{ echo | ||
colorize 1 "WARNING" | ||
echo ": seems you still have not added 'pyenv' to the load path." | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the heck did we export
--detect-shell
, to be used witheval
to boot, if we STILL need this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#137 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering this example:
Run
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
in zsh.Just to make sure this scenario would work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That just means that
--detect-shell
needs to do better.Thanks to
eval
, it can run code in the same process, evading the "shell of parent of parent" problem.Just make it output the shell detection code that you've copypasted.