Fix shell_contains, setting _python_command to shim

This commit is contained in:
Ivan Malison 2016-09-06 15:04:19 -07:00
parent bd31127601
commit 2baa68780c
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8
3 changed files with 25 additions and 14 deletions

View File

@ -1,18 +1,30 @@
_python_command="" function command_exists {
hash "$1" 2>/dev/null 1>/dev/null
}
function shell_contains () {
local e
for e in "${@:2}"; do
[[ "$1" == *"$e"* ]] && return 0
done
return 1
}
function _set_python_command { function _set_python_command {
# See comment in add_to_path about why this is necessary # See comment in add_to_path about why this is necessary
if hash pyenv 2>/dev/null; if command_exists pyenv;
then then
_python_command="$(pyenv which python)" _python_command="$(pyenv which python)"
else else
which pyenv
_python_command="$(which python)" _python_command="$(which python)"
fi fi
shell_contains "$_python_command" "shim" && \
echo "Warning: setting python command to shim"
} }
_set_python_command
function add_to_path { function add_to_path {
environment_variable_exists _python_command || _set_python_command
# We need to get a path to the ACTUAL python command because # We need to get a path to the ACTUAL python command because
# pyenv alters PATH before actually executing python, which ends # pyenv alters PATH before actually executing python, which ends
# up changing PATH in a way that is not desireable. # up changing PATH in a way that is not desireable.
@ -64,10 +76,6 @@ function environment_variable_exists {
[ ! -z $value ] [ ! -z $value ]
} }
function command_exists {
hash "$1" 2>/dev/null 1>/dev/null
}
function source_directory_files { function source_directory_files {
for filename in "$1"/*; do for filename in "$1"/*; do
environment_variable_exists SHELL_STARTUP_DEBUG && echo "Sourcing $filename" environment_variable_exists SHELL_STARTUP_DEBUG && echo "Sourcing $filename"

View File

@ -50,7 +50,9 @@ EOF
function shell_contains () { function shell_contains () {
local e local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done for e in "${@:2}"; do
[[ "$1" == *"$e"* ]] && return 0
done
return 1 return 1
} }

View File

@ -3,12 +3,12 @@ source "$HOME/.lib/setup_functions.sh"
function _setup_env { function _setup_env {
_path_helper _path_helper
add_to_path "$HOME/.local/bin" "$HOME/.lib/bin" "$HOME/bin" "/usr/local/bin" --before
_ruby_setup
# XXX/TODO: # XXX/TODO:
# This is in shellenv.sh now # This is in shellenv.sh now
# _python_setup _python_setup
add_to_path "$HOME/.local/bin" "$HOME/.lib/bin" "$HOME/bin" "/usr/local/bin" --before
_ruby_setup
is_osx && _osx_path_setup is_osx && _osx_path_setup
_emacs_setup _emacs_setup
@ -38,7 +38,6 @@ function _osx_path_setup {
} }
function _python_setup { function _python_setup {
add_to_path "$HOME/.lib/python" --after
export PYENV_ROOT="/usr/local/var/pyenv" export PYENV_ROOT="/usr/local/var/pyenv"
if which pyenv > /dev/null; then if which pyenv > /dev/null; then
@ -47,6 +46,7 @@ function _python_setup {
echo "WARNING: pyenv is not installed on this machine and python will likely not function correctly" echo "WARNING: pyenv is not installed on this machine and python will likely not function correctly"
fi fi
add_to_path "$HOME/.lib/python" --after
# if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi # if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
add_to_path "$HOME/.lib/python" --path-var 'PYTHONPATH' add_to_path "$HOME/.lib/python" --path-var 'PYTHONPATH'
@ -115,3 +115,4 @@ function _path_helper {
eval "$(/usr/libexec/path_helper -s)" eval "$(/usr/libexec/path_helper -s)"
fi fi
} }