forked from colonelpanic/dotfiles
Refactor zsh_env startup so that it is possible to override PATH
variable once it has already been configured.
This commit is contained in:
parent
f76b446ccf
commit
b83433a807
@ -1,21 +1,29 @@
|
||||
source ~/.lib/shellenv/functions.sh
|
||||
command -v greadlink > /dev/null && alias readlink="greadlink"
|
||||
|
||||
add_to_back_of_path "$HOME/.local/lib/python2.6/site-packages"
|
||||
add_to_back_of_path "$HOME/.rvm/bin"
|
||||
add_to_front_of_path "$HOME/bin"
|
||||
hash brew 2>/dev/null && add_to_front_of_path "$(brew --prefix coreutils)/libexec/gnubin"
|
||||
add_to_front_of_path "/usr/local/bin"
|
||||
function _source_shellenv_files {
|
||||
for filename in ~/.lib/shellenv/*; do
|
||||
source $filename
|
||||
done
|
||||
}
|
||||
|
||||
function _setup_env {
|
||||
idem_add_to_back_of_path "$HOME/.local/lib/python2.6/site-packages"
|
||||
idem_add_to_back_of_path "$HOME/.rvm/bin"
|
||||
idem_add_to_front_of_path "$HOME/bin"
|
||||
hash brew 2>/dev/null && idem_add_to_front_of_path "$(brew --prefix coreutils)/libexec/gnubin"
|
||||
idem_add_to_front_of_path "/usr/local/bin"
|
||||
|
||||
if is_osx; then
|
||||
export CFLAGS=-Qunused-arguments
|
||||
export CPPFLAGS=-Qunused-arguments
|
||||
add_to_back_of_path "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources"
|
||||
idem_add_to_back_of_path "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources"
|
||||
local JDK_LOCATION="$(find /Library/Java/JavaVirtualMachines -depth 1 | head -n 1)"
|
||||
export JAVA_HOME="$JDK_LOCATION/Contents/Home"
|
||||
export STUDIO_JDK=$JDK_LOCATION
|
||||
export GRADLE_HOME="$(brew --prefix gradle)"
|
||||
export ANDROID_HOME="$(brew --prefix android-sdk)"
|
||||
add_to_back_of_path "$ANDROID_HOME"
|
||||
idem_add_to_back_of_path "$ANDROID_HOME"
|
||||
|
||||
# Access gnu man pages.
|
||||
hash brew 2> /dev/null && export MANPATH="$(brew --prefix)/opt/coreutils/libexec/gnuman:$MANPATH"
|
||||
@ -24,17 +32,15 @@ else
|
||||
is_osx && export VISUAL="which emacsclient -c -n"
|
||||
fi
|
||||
|
||||
add_to_front_of_path "$JAVA_HOME/bin"
|
||||
idem_add_to_front_of_path "$JAVA_HOME/bin"
|
||||
|
||||
add_to_back_of_path "$(dotfiles_directory)/resources/python"
|
||||
add_to_back_of_path "/usr/local/sbin"
|
||||
idem_add_to_back_of_path "$(dotfiles_directory)/resources/python"
|
||||
idem_add_to_back_of_path "/usr/local/sbin"
|
||||
|
||||
# Load RVM into a shell session *as a function*
|
||||
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
|
||||
|
||||
for filename in ~/.lib/shellenv/*; do
|
||||
source $filename
|
||||
done
|
||||
_source_shellenv_files
|
||||
|
||||
function with_shellrc {
|
||||
zsh -c "source ~/.zshrc && ""$@"
|
||||
@ -50,9 +56,18 @@ export NVM_DIR="/Users/imalison/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
|
||||
export NODE_PATH="/usr/local/lib/node_modules/"
|
||||
|
||||
add_to_front_of_path "$HOME/.lib/python" 'PYTHONPATH'
|
||||
idem_add_to_front_of_path "$HOME/.local/bin"
|
||||
idem_add_to_front_of_path "$HOME/.lib/python" 'PYTHONPATH'
|
||||
|
||||
export RBENV_ROOT=/usr/local/var/rbenv
|
||||
add_to_front_of_path "$HOME/.rbenv/bin"
|
||||
idem_add_to_front_of_path "$HOME/.rbenv/bin"
|
||||
hash rbenv 2> /dev/null && eval "$(rbenv init -)"
|
||||
hash brew 2>/dev/null && add_to_front_of_path "$(brew --prefix coreutils)/libexec/gnubin"
|
||||
hash brew 2>/dev/null && idem_add_to_front_of_path "$(brew --prefix coreutils)/libexec/gnubin"
|
||||
export ENVIRONMENT_SETUP_DONE="$(date)"
|
||||
}
|
||||
|
||||
if [ -z ${ENVIRONMENT_SETUP_DONE+x} ]; then
|
||||
_setup_env
|
||||
else
|
||||
_source_shellenv_files
|
||||
fi
|
||||
|
@ -33,6 +33,32 @@ function add_to_back_of_path {
|
||||
export $target="$(_add_to_back_of_path_lines $1 $target | tr '\n' ':' | remove_trailing_colon)"
|
||||
}
|
||||
|
||||
function idem_add_to_front_of_path {
|
||||
target=${2-PATH}
|
||||
exists_in_path_var $1 $target || add_to_front_of_path $1 $target
|
||||
}
|
||||
|
||||
function idem_add_to_back_of_path {
|
||||
target=${2-PATH}
|
||||
exists_in_path_var $1 $target || add_to_back_of_path $1 $target
|
||||
}
|
||||
|
||||
function indirect_expand {
|
||||
eval "value=\"\${$1}\""
|
||||
echo $value
|
||||
}
|
||||
|
||||
function environment_variable_exists {
|
||||
eval "value=\"\${$1+x}\""
|
||||
[ ! -z $value ]
|
||||
}
|
||||
|
||||
function exists_in_path_var {
|
||||
target=${2-PATH}
|
||||
local path_contents="$(indirect_expand $target)"
|
||||
[[ ":$path_contents:" == *":$1:"* ]]
|
||||
}
|
||||
|
||||
function split_into_vars () {
|
||||
local string IFS
|
||||
|
||||
@ -347,6 +373,7 @@ function parse_timestamp {
|
||||
}
|
||||
|
||||
function refresh_config {
|
||||
unset ENVIRONMENT_SETUP_DONE
|
||||
source ~/.zshenv
|
||||
source ~/.zshrc
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ export UBER_OWNER="imalison@uber.com"
|
||||
[ -z "$GIT_SSH" ] || export GIT_SSH="$HOME/.lib/git-ssh.sh"
|
||||
export VAGRANT_DEFAULT_PROVIDER=aws
|
||||
[ -s "/usr/local/bin/virtualenvwrapper.sh" ] && . /usr/local/bin/virtualenvwrapper.sh
|
||||
[ -s "$HOME/.nvm/nvm.sh" ] && . $HOME/.nvm/nvm.sh
|
||||
|
||||
cdsync () {
|
||||
cd $(boxer sync_dir $@)
|
||||
|
@ -1 +1,11 @@
|
||||
function init_profile {
|
||||
zmodload zsh/datetime
|
||||
setopt promptsubst
|
||||
PS4='+$EPOCHREALTIME %N:%i> '
|
||||
# save file stderr to file descriptor 3 and redirect stderr (including trace
|
||||
# output) to a file with the script's PID as an extension
|
||||
exec 3>&2 2>/tmp/startlog.$$
|
||||
# set options to turn on tracing and expansion of commands contained in the prompt
|
||||
setopt xtrace prompt_subst
|
||||
}
|
||||
source ~/.lib/shellenv.sh
|
Loading…
Reference in New Issue
Block a user