diff --git a/dotfiles/lib/setup_functions.sh b/dotfiles/lib/setup_functions.sh index 47321fab..97393484 100644 --- a/dotfiles/lib/setup_functions.sh +++ b/dotfiles/lib/setup_functions.sh @@ -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 { # See comment in add_to_path about why this is necessary - if hash pyenv 2>/dev/null; + if command_exists pyenv; then _python_command="$(pyenv which python)" else + which pyenv _python_command="$(which python)" fi + shell_contains "$_python_command" "shim" && \ + echo "Warning: setting python command to shim" } -_set_python_command - function add_to_path { + environment_variable_exists _python_command || _set_python_command # We need to get a path to the ACTUAL python command because # pyenv alters PATH before actually executing python, which ends # up changing PATH in a way that is not desireable. @@ -64,10 +76,6 @@ function environment_variable_exists { [ ! -z $value ] } -function command_exists { - hash "$1" 2>/dev/null 1>/dev/null -} - function source_directory_files { for filename in "$1"/*; do environment_variable_exists SHELL_STARTUP_DEBUG && echo "Sourcing $filename" diff --git a/dotfiles/lib/shellenv/functions.sh b/dotfiles/lib/shellenv/functions.sh index 5b5e65fe..fb5a9ec4 100644 --- a/dotfiles/lib/shellenv/functions.sh +++ b/dotfiles/lib/shellenv/functions.sh @@ -50,7 +50,9 @@ EOF function shell_contains () { local e - for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done + for e in "${@:2}"; do + [[ "$1" == *"$e"* ]] && return 0 + done return 1 } diff --git a/dotfiles/lib/shellpath.sh b/dotfiles/lib/shellpath.sh index c8fcd9f2..de132c3e 100644 --- a/dotfiles/lib/shellpath.sh +++ b/dotfiles/lib/shellpath.sh @@ -3,12 +3,12 @@ source "$HOME/.lib/setup_functions.sh" function _setup_env { _path_helper - add_to_path "$HOME/.local/bin" "$HOME/.lib/bin" "$HOME/bin" "/usr/local/bin" --before - _ruby_setup - # XXX/TODO: # 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 _emacs_setup @@ -38,7 +38,6 @@ function _osx_path_setup { } function _python_setup { - add_to_path "$HOME/.lib/python" --after export PYENV_ROOT="/usr/local/var/pyenv" 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" fi + add_to_path "$HOME/.lib/python" --after # if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi add_to_path "$HOME/.lib/python" --path-var 'PYTHONPATH' @@ -115,3 +115,4 @@ function _path_helper { eval "$(/usr/libexec/path_helper -s)" fi } +