Skip to content
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

[WIP] automatically add to path #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ Uninstall:
.. code:: bash
rm -fr ~/.pyenv
then remove these three lines from ``.bashrc``:
then remove these three lines from your shell config file(``.bashrc``, ``.zshrc``, ``.profile``...):

.. code:: bash
Expand Down
83 changes: 74 additions & 9 deletions bin/pyenv-installer
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if [ -z "$PYENV_ROOT" ]; then
export PYENV_ROOT="${HOME}/.pyenv"
fi

SRC_WRITTEN=false

colorize() {
if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
else echo -n "$2"
Expand Down Expand Up @@ -50,15 +52,78 @@ 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"

if ! command -v pyenv 1>/dev/null; then
{ echo
colorize 1 "WARNING"
echo ": seems you still have not added 'pyenv' to the load path."
echo
write_source() {
{
echo "Appending the following lines to $1:"
echo ' # pyenv'
echo ' export PATH="'"$PYENV_ROOT/bin:"'$PATH"'
echo ' eval "$(pyenv init --path)"'
echo ' eval "$(pyenv virtualenv-init -)"'
echo ''
} >&2

{ # Without args, `init` commands print installation help
"${PYENV_ROOT}/bin/pyenv" init || true
"${PYENV_ROOT}/bin/pyenv" virtualenv-init || true
} >&2
echo "" >>$1
echo '# pyenv' >>$1
echo 'export PATH="'"$PYENV_ROOT/bin:"'$PATH"' >>$1
echo 'eval "$(pyenv init --path)"' >>$1
echo 'eval "$(pyenv virtualenv-init -)"' >>$1

SRC_WRITTEN=true
}

add_userpath() {
OS="$(uname -s)"
CURRENT_SHELL="$(basename "$SHELL")"

if [[ "$OS" = "Darwin" ]]; then
if [[ "$CURRENT_SHELL" = "zsh" ]]; then
write_source "$HOME/.zprofile"
elif [[ "$CURRENT_SHELL" = "bash" ]]; then
write_source "$HOME/.bash_profile"
fi

elif [[ "$CURRENT_SHELL" = "zsh" ]]; then
# write to first match: zshrc/zprofile
if [[ -f $HOME/.zshrc ]]; then
write_source "$HOME/.zshrc"
elif [[ -f $HOME/.zprofile ]]; then
write_source "$HOME/.zprofile"
fi

elif [[ "$CURRENT_SHELL" = "bash" ]]; then
# bashrc
write_source "$HOME/.bashrc"

# write to first match: profile/bash_profile
if [[ -f $HOME/.profile ]]; then
write_source "$HOME/.profile"
elif [[ -f $HOME/.bash_profile ]]; then
write_source "$HOME/.bash_profile"
fi

else
{
echo "Add userpath for $CURRENT_SHELL is not currently supported"
echo "Please set up manually"
} >&2
fi
}

if ! command -v pyenv 1>/dev/null; then
add_userpath

if ${SRC_WRITTEN}; then
echo "Close and reopen your terminal to start using pyenv" >&2
else
{ echo
colorize 1 "WARNING"
echo ": seems you still have not added 'pyenv' to the load path."
echo
} >&2

{ # Without args, `init` commands print installation help
"${PYENV_ROOT}/bin/pyenv" init || true
"${PYENV_ROOT}/bin/pyenv" virtualenv-init || true
} >&2
fi
fi
82 changes: 73 additions & 9 deletions bin/pyenv-offline-installer
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if [ -z "$PYENV_ROOT" ]; then
PYENV_ROOT="${HOME}/.pyenv"
fi

SRC_WRITTEN=false

colorize() {
if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
else echo -n "$2"
Expand Down Expand Up @@ -60,16 +62,78 @@ conditional_mv "$TMP_DIR/pyenv-which-ext" "${PYENV_ROOT}/plugins/pyenv-which-ex

rm -rf $TMP_DIR

write_source() {
{
echo "Appending the following lines to $1:"
echo ' # pyenv'
echo ' export PATH="'"$PYENV_ROOT/bin:"'$PATH"'
echo ' eval "$(pyenv init --path)"'
echo ' eval "$(pyenv virtualenv-init -)"'
echo ''
} >&2

echo "" >>$1
echo '# pyenv' >>$1
echo 'export PATH="'"$PYENV_ROOT/bin:"'$PATH"' >>$1
echo 'eval "$(pyenv init --path)"' >>$1
echo 'eval "$(pyenv virtualenv-init -)"' >>$1

SRC_WRITTEN=true
}

add_userpath() {
OS="$(uname -s)"
CURRENT_SHELL="$(basename "$SHELL")"

if [[ "$OS" = "Darwin" ]]; then
if [[ "$CURRENT_SHELL" = "zsh" ]]; then
write_source "$HOME/.zprofile"
elif [[ "$CURRENT_SHELL" = "bash" ]]; then
write_source "$HOME/.bash_profile"
fi

elif [[ "$CURRENT_SHELL" = "zsh" ]]; then
# write to first match: zshrc/zprofile
if [[ -f $HOME/.zshrc ]]; then
write_source "$HOME/.zshrc"
elif [[ -f $HOME/.zprofile ]]; then
write_source "$HOME/.zprofile"
fi

elif [[ "$CURRENT_SHELL" = "bash" ]]; then
# bashrc
write_source "$HOME/.bashrc"

# write to first match: profile/bash_profile
if [[ -f $HOME/.profile ]]; then
write_source "$HOME/.profile"
elif [[ -f $HOME/.bash_profile ]]; then
write_source "$HOME/.bash_profile"
fi

else
{
echo "Add userpath for $CURRENT_SHELL is not currently supported"
echo "Please set up manually"
} >&2
fi
}

if ! command -v pyenv 1>/dev/null; then
{ echo
colorize 1 "WARNING"
echo ": seems you still have not added 'pyenv' to the load path."
echo
} >&2
add_userpath

{ # Without args, `init` commands print installation help
"${PYENV_ROOT}/bin/pyenv" init || true
"${PYENV_ROOT}/bin/pyenv" virtualenv-init || true
} >&2
if ${SRC_WRITTEN}; then
echo "Close and reopen your terminal to start using pyenv" >&2
else
{ echo
colorize 1 "WARNING"
echo ": seems you still have not added 'pyenv' to the load path."
echo
} >&2

{ # Without args, `init` commands print installation help
"${PYENV_ROOT}/bin/pyenv" init || true
"${PYENV_ROOT}/bin/pyenv" virtualenv-init || true
} >&2
fi
fi