From 2404216ccd8314888dde1b7ee95f2a7a862901c8 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Wed, 30 May 2018 14:54:22 -0700 Subject: [PATCH 1/3] Only make path setup permanent from login.sh --- dotfiles/lib/login.sh | 5 +++++ dotfiles/lib/{shellenv => login}/exports.sh | 0 dotfiles/lib/setup_functions.sh | 15 ++++++++++----- dotfiles/lib/shellenv.sh | 21 --------------------- dotfiles/lib/shellpath.sh | 8 +++----- dotfiles/lib/shellrc.sh | 19 +++++++++++++++---- dotfiles/xprofile | 2 +- 7 files changed, 34 insertions(+), 36 deletions(-) create mode 100644 dotfiles/lib/login.sh rename dotfiles/lib/{shellenv => login}/exports.sh (100%) delete mode 100644 dotfiles/lib/shellenv.sh diff --git a/dotfiles/lib/login.sh b/dotfiles/lib/login.sh new file mode 100644 index 00000000..1e7b4bf8 --- /dev/null +++ b/dotfiles/lib/login.sh @@ -0,0 +1,5 @@ +source "$HOME/.lib/shellpath.sh" + +setup_unless_environment_variable_exists ENV_PATH_SETUP_DONE || _setup_path + +source_directory_files "$HOME/.lib/login" diff --git a/dotfiles/lib/shellenv/exports.sh b/dotfiles/lib/login/exports.sh similarity index 100% rename from dotfiles/lib/shellenv/exports.sh rename to dotfiles/lib/login/exports.sh diff --git a/dotfiles/lib/setup_functions.sh b/dotfiles/lib/setup_functions.sh index 395c8bbf..f8b2ccba 100644 --- a/dotfiles/lib/setup_functions.sh +++ b/dotfiles/lib/setup_functions.sh @@ -27,6 +27,16 @@ function _set_python_command { echo "Warning: setting python command to shim" } +function environment_variable_exists { + eval "value=\"\${$1+x}\"" + [ ! -z $value ] +} + +function setup_unless_environment_variable_exists { + environment_variable_exists "$1" || $2 + export "$1=$(date)" +} + function add_to_path { environment_variable_exists _python_command || _set_python_command # We need to get a path to the ACTUAL python command because @@ -75,11 +85,6 @@ function is_osx() { esac } -function environment_variable_exists { - eval "value=\"\${$1+x}\"" - [ ! -z $value ] -} - function source_directory_files { for filename in "$1"/*; do environment_variable_exists SHELL_STARTUP_DEBUG && echo "Sourcing $filename" diff --git a/dotfiles/lib/shellenv.sh b/dotfiles/lib/shellenv.sh deleted file mode 100644 index 01ff199a..00000000 --- a/dotfiles/lib/shellenv.sh +++ /dev/null @@ -1,21 +0,0 @@ -source "$HOME/.lib/shellpath.sh" - -environment_variable_exists ENVIRONMENT_SETUP_DONE || _setup_env - -# TODO(imalison): These need to run every time because of how their -# version managers work. This could cause problems with the situation -# where we want to intentionally override the python/ruby/node -# versions in use in a given shell. - -# TODO: Ruby and node are disabled to speed up shell startup... -# See https://github.com/creationix/nvm/issues/709 for nvm -# _node_setup - -# XXX: these were moved to _setup_env -# _ruby_setup -_python_setup - -source_directory_files "$HOME/.lib/shellenv" - -test -r ~/.customenv.sh && source ~/.customenv.sh -source_if_exists ~/.this-machine-env.sh diff --git a/dotfiles/lib/shellpath.sh b/dotfiles/lib/shellpath.sh index f57e1e44..0815cafa 100644 --- a/dotfiles/lib/shellpath.sh +++ b/dotfiles/lib/shellpath.sh @@ -1,6 +1,6 @@ source "$HOME/.lib/setup_functions.sh" -function _setup_env { +function _setup_path { _path_helper # XXX/TODO: @@ -20,13 +20,11 @@ function _setup_env { _rust_setup _tex_setup - # This makes systemd aware of change to $PATH - run_if_exists systemctl --user import-environment PATH DISPLAY XAUTHORITY HOME - # To ensure that things in ~/.lib/bin take precedence add_to_path "$HOME/.lib/bin" --before - export ENVIRONMENT_SETUP_DONE="$(date)" + # This makes systemd aware of change to $PATH + run_if_exists systemctl --user import-environment PATH DISPLAY XAUTHORITY HOME } function _linux_path_setup { diff --git a/dotfiles/lib/shellrc.sh b/dotfiles/lib/shellrc.sh index ea984f4e..f448ef47 100644 --- a/dotfiles/lib/shellrc.sh +++ b/dotfiles/lib/shellrc.sh @@ -10,11 +10,22 @@ function j() { } environment_variable_exists INSIDE_EMACS && inside_emacs_hook -# XXX: This used to be in shellenv and should be moved back once these -# are faster. -_node_setup -_ruby_setup +# TODO(imalison): These need to run every time because of how their +# version managers work. This could cause problems with the situation +# where we want to intentionally override the python/ruby/node +# versions in use in a given shell. + +# TODO: Ruby and node are disabled to speed up shell startup... +# See https://github.com/creationix/nvm/issues/709 for nvm +# _node_setup + +# XXX: these were moved to _setup_env +# _ruby_setup +# _python_setup +# _node_setup +# _ruby_setup # travis completion # XXX: Disabled to reduce performance impact # [ -f "$HOME/.travis/travis.sh" ] && source "$HOME/.travis/travis.sh" + diff --git a/dotfiles/xprofile b/dotfiles/xprofile index c4c781fa..95704b81 100644 --- a/dotfiles/xprofile +++ b/dotfiles/xprofile @@ -1,7 +1,7 @@ # -*- mode: sh; -*- # If there are issues with path, check /etc/profile for hard overrides of PATH. -source "$HOME/.lib/shellenv.sh" +source "$HOME/.lib/login.sh" # XXX: prevents https://github.com/xmonad/xmonad/issues/86 from affecting startup rm -f ~/.xmonad/xmonad.state load_xkb_map.sh From 8d9870404dae3a0a5c8fe6dcd41c0dd0e9f234f8 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Wed, 30 May 2018 22:11:41 -0700 Subject: [PATCH 2/3] Update PATH configuration for NixOS --- dotfiles/bash_profile | 2 +- dotfiles/lib/login.sh | 3 ++- dotfiles/lib/nix_login.sh | 4 ++++ dotfiles/lib/shellenv.sh | 12 ++++++++++++ dotfiles/zprofile | 1 + rcm-link.sh | 2 +- 6 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 dotfiles/lib/nix_login.sh create mode 100644 dotfiles/lib/shellenv.sh create mode 100644 dotfiles/zprofile diff --git a/dotfiles/bash_profile b/dotfiles/bash_profile index 86795d70..6cd8b53a 100644 --- a/dotfiles/bash_profile +++ b/dotfiles/bash_profile @@ -1 +1 @@ -source ~/.bashrc +source ~/.lib/login.sh diff --git a/dotfiles/lib/login.sh b/dotfiles/lib/login.sh index 1e7b4bf8..0a82b36c 100644 --- a/dotfiles/lib/login.sh +++ b/dotfiles/lib/login.sh @@ -1,5 +1,6 @@ source "$HOME/.lib/shellpath.sh" -setup_unless_environment_variable_exists ENV_PATH_SETUP_DONE || _setup_path +# XXX: This is duplicated from env with a different var to avoid issues with /etc/profile +command_exists python && setup_unless_environment_variable_exists LOGIN_PATH_SETUP_DONE _setup_path source_directory_files "$HOME/.lib/login" diff --git a/dotfiles/lib/nix_login.sh b/dotfiles/lib/nix_login.sh new file mode 100644 index 00000000..ccf4f046 --- /dev/null +++ b/dotfiles/lib/nix_login.sh @@ -0,0 +1,4 @@ +source "$HOME/.lib/shellpath.sh" + +command_exists python && setup_unless_environment_variable_exists NIX_PATH_SETUP_DONE _setup_path + diff --git a/dotfiles/lib/shellenv.sh b/dotfiles/lib/shellenv.sh new file mode 100644 index 00000000..8fe71607 --- /dev/null +++ b/dotfiles/lib/shellenv.sh @@ -0,0 +1,12 @@ +source "$HOME/.lib/shellpath.sh" + +# XXX: This PATH setup var is only actually set in login.sh which is definitely +# strange. The reason for this is that because env runs BEFORE profile, things +# in places like /etc/profile can actually clobber the path setup that we do. + +# Disbled setup here. Doing it in profile instead +if command_exists python; then + environment_variable_exists LOGIN_PATH_SETUP_DONE || setup_unless_environment_variable_exists ENV_PATH_SETUP_DONE _setup_path +fi + +source_directory_files "$HOME/.lib/shellenv" diff --git a/dotfiles/zprofile b/dotfiles/zprofile new file mode 100644 index 00000000..6cd8b53a --- /dev/null +++ b/dotfiles/zprofile @@ -0,0 +1 @@ +source ~/.lib/login.sh diff --git a/rcm-link.sh b/rcm-link.sh index f9154001..d17fe704 100755 --- a/rcm-link.sh +++ b/rcm-link.sh @@ -5,4 +5,4 @@ export THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" export DOTFILES_DIR="$(readlink -f $THIS_DIR/dotfiles)" echo $DOTFILES_DIR -rcup -d $DOTFILES_DIR -S "emacs.d" -S "config/taffybar" -S "config/xmonad" -S "config/xmonad/taffybar" +rcup -d $DOTFILES_DIR -S "emacs.d" -S "config/taffybar" -S "config/xmonad" -S "config/xmonad/taffybar" -S "lib" From 403643f980af5424e56e34afb4bc93d59ecd9c39 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Wed, 30 May 2018 22:18:15 -0700 Subject: [PATCH 3/3] Remove pyenv and other NixOS tweaks --- dotfiles/lib/setup_functions.sh | 47 +++++++++++++-------------------- dotfiles/lib/shellpath.sh | 15 +---------- dotfiles/xprofile | 4 ++- 3 files changed, 23 insertions(+), 43 deletions(-) diff --git a/dotfiles/lib/setup_functions.sh b/dotfiles/lib/setup_functions.sh index f8b2ccba..e98a4d67 100644 --- a/dotfiles/lib/setup_functions.sh +++ b/dotfiles/lib/setup_functions.sh @@ -14,35 +14,17 @@ function shell_contains () { return 1 } -function _set_python_command { - # See comment in add_to_path about why this is necessary - 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" -} - function environment_variable_exists { eval "value=\"\${$1+x}\"" [ ! -z $value ] } function setup_unless_environment_variable_exists { - environment_variable_exists "$1" || $2 - export "$1=$(date)" + environment_variable_exists "$1" || { $2 && export "$1=$(date)"; } } 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. - eval "$($_python_command $HOME/.lib/python/shell_path.py --include-assignment "$@")" + eval "$(python $HOME/.lib/python/shell_path.py --include-assignment "$@")" } # Taken from http://www.unix.com/shell-programming-and-scripting/27932-how-know-linux-distribution-i-am-using.html @@ -65,6 +47,11 @@ function get_linux_distro { [ -n "$dist" ] && echo "$dist" && return 0 fi + if [ -r /etc/os-release ]; then + dist=$(grep 'ID=' /etc/os-release | sed 's/ID=//' | head -1) + [ -n "$dist" ] && echo "$dist" && return 0 + fi + dist=$(find /etc/ -maxdepth 1 -name '*release' 2> /dev/null | sed 's/\/etc\///' | sed 's/-release//' | head -1) [ -n "$dist" ] && echo "$dist" && return 0 @@ -75,14 +62,18 @@ function get_linux_distro { function is_osx() { - case `uname` in - 'Darwin') - return 0 - ;; - *) - return 1; - ;; - esac + if command_exists uname; then + case `uname` in + 'Darwin') + return 0; + ;; + *) + return 1; + ;; + esac + else + return 1 + fi } function source_directory_files { diff --git a/dotfiles/lib/shellpath.sh b/dotfiles/lib/shellpath.sh index 0815cafa..4243636e 100644 --- a/dotfiles/lib/shellpath.sh +++ b/dotfiles/lib/shellpath.sh @@ -3,10 +3,6 @@ source "$HOME/.lib/setup_functions.sh" function _setup_path { _path_helper - # XXX/TODO: - # This is in shellenv.sh now - _python_setup - add_to_path "$HOME/.lib/bin" "$HOME/.local/bin" "$HOME/bin" --before add_to_path "/usr/local/sbin" "/usr/local/bin" "/usr/bin" --after _ruby_setup @@ -16,6 +12,7 @@ function _setup_path { _haskell_setup _java_setup _go_setup + _python_setup _racket_setup _rust_setup _tex_setup @@ -49,17 +46,7 @@ function _osx_path_setup { } function _python_setup { - export PYENV_ROOT="/usr/local/var/pyenv" - - if which pyenv > /dev/null; then - eval "$(pyenv init - --no-rehash)" - else - 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' } diff --git a/dotfiles/xprofile b/dotfiles/xprofile index 95704b81..34526974 100644 --- a/dotfiles/xprofile +++ b/dotfiles/xprofile @@ -1,7 +1,9 @@ # -*- mode: sh; -*- + # If there are issues with path, check /etc/profile for hard overrides of PATH. -source "$HOME/.lib/login.sh" +. "$HOME/.lib/login.sh" # XXX: prevents https://github.com/xmonad/xmonad/issues/86 from affecting startup + rm -f ~/.xmonad/xmonad.state load_xkb_map.sh