2018-06-15 13:43:04 +00:00
|
|
|
#!/usr/bin/env zsh
|
2018-02-23 09:38:24 +00:00
|
|
|
|
2021-02-13 14:39:18 +00:00
|
|
|
export PATH
|
|
|
|
export MANPATH
|
2020-04-18 11:53:08 +00:00
|
|
|
|
2021-02-13 14:39:18 +00:00
|
|
|
# tie these env variables to zsh arrays
|
|
|
|
export -T PKG_CONFIG_PATH pkg_config_path ':'
|
|
|
|
export -T LD_LIBRARY_PATH ld_library_path ':'
|
2019-10-06 10:24:46 +00:00
|
|
|
|
|
|
|
path_prepend() {
|
2020-07-26 10:01:53 +00:00
|
|
|
if (( $# < 1 )); then
|
2020-01-05 11:43:46 +00:00
|
|
|
print >&2 "usage: $0 <var_name> <value...>"
|
|
|
|
return 1
|
2019-10-06 10:24:46 +00:00
|
|
|
fi
|
2020-01-05 11:43:46 +00:00
|
|
|
local var_name="$1"; shift
|
|
|
|
local value; for value in "$@"; do
|
2021-01-25 16:37:50 +00:00
|
|
|
if eval "(( \${${var_name}[(ie)\$value]-1} > \${#${var_name}} ))"; then
|
2020-01-05 11:43:46 +00:00
|
|
|
eval "${var_name}=(\"\$value\" \"\${${var_name}[@]}\")"
|
|
|
|
fi
|
|
|
|
done
|
2019-10-06 10:24:46 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 13:28:23 +00:00
|
|
|
# glob modifiers used in this script:
|
|
|
|
#
|
|
|
|
# N - enables the null_glob option for a single glob pattern, in other words
|
|
|
|
# ignores an error when the pattern didn't match anything
|
|
|
|
#
|
|
|
|
# / - matches only directories
|
2018-11-13 06:05:03 +00:00
|
|
|
|
2020-08-28 13:28:23 +00:00
|
|
|
if (( _is_macos )); then
|
2020-01-05 11:43:46 +00:00
|
|
|
# GNU counterparts of command line utilities
|
2020-08-28 13:28:23 +00:00
|
|
|
path_prepend path /usr/local/opt/*/libexec/gnubin(N/)
|
|
|
|
path_prepend manpath /usr/local/opt/*/libexec/gnuman(N/)
|
2019-05-01 14:40:25 +00:00
|
|
|
|
2020-01-05 11:43:46 +00:00
|
|
|
# add some keg-only Homebrew formulas
|
|
|
|
for formula in curl file-formula openssl ruby; do
|
2019-05-11 11:54:20 +00:00
|
|
|
formula_path="/usr/local/opt/$formula"
|
2020-01-05 11:43:46 +00:00
|
|
|
if [[ ! -d "$formula_path" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -d "$formula_path/bin" ]]; then
|
|
|
|
path_prepend path "$formula_path/bin"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -d "$formula_path/lib/pkgconfig" ]]; then
|
|
|
|
path_prepend pkg_config_path "$formula_path/lib/pkgconfig"
|
2019-05-11 11:54:20 +00:00
|
|
|
fi
|
2021-02-07 17:49:38 +00:00
|
|
|
done; unset formula
|
2020-01-05 11:43:46 +00:00
|
|
|
|
2021-02-07 17:49:38 +00:00
|
|
|
# Use Python 3 executables by default, i.e. when a version suffix (`python3`)
|
|
|
|
# is not specified.
|
|
|
|
path_prepend path /usr/local/opt/python@3/libexec/bin
|
2018-02-23 09:38:24 +00:00
|
|
|
fi
|
|
|
|
|
2020-08-28 13:28:23 +00:00
|
|
|
if (( _is_macos )); then
|
|
|
|
# Python packages (for some reason they don't go into ~/.local/bin, but
|
|
|
|
# instead into the garbage ~/Library directory)
|
|
|
|
path_prepend path ~/Library/Python/*/bin(N/)
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ruby gems
|
|
|
|
path_prepend path ~/.gem/ruby/*/bin(N/)
|
|
|
|
|
2019-10-06 10:24:46 +00:00
|
|
|
# Yarn global packages
|
2020-01-05 11:43:46 +00:00
|
|
|
path_prepend path ~/.yarn/bin
|
2019-10-06 10:24:46 +00:00
|
|
|
|
|
|
|
# Go
|
2020-08-28 13:28:23 +00:00
|
|
|
export GOPATH=~/go
|
2020-01-05 11:43:46 +00:00
|
|
|
path_prepend path "$GOPATH/bin"
|
2018-11-28 19:00:09 +00:00
|
|
|
|
2019-09-24 19:34:15 +00:00
|
|
|
# Rust
|
2021-02-12 19:00:01 +00:00
|
|
|
if [[ -f ~/.rustup/settings.toml ]]; then
|
|
|
|
# Make a low-effort attempt at quickly extracting the selected Rust toolchain
|
|
|
|
# from rustup's settings. The TOML file is obviously assumed to be well-formed
|
|
|
|
# and syntactically correct because virtually always it's manipulated with the
|
|
|
|
# use of rustup's CLI. Also a shortcut is taken: strings aren't unescaped
|
|
|
|
# because Rust toolchain names don't need escaping in strings.
|
|
|
|
# See also <https://github.com/toml-lang/toml/blob/master/toml.abnf>.
|
2021-02-13 15:31:01 +00:00
|
|
|
rust_toolchain=""
|
|
|
|
< ~/.rustup/settings.toml while IFS= read -r line; do
|
|
|
|
if [[ "$line" =~ '^default_toolchain = "(.+)"$' ]]; then
|
|
|
|
rust_toolchain="${match[1]}"
|
|
|
|
break
|
|
|
|
elif [[ "$line" == \[*\] ]]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done; unset line
|
|
|
|
|
|
|
|
if [[ -n "$rust_toolchain" ]]; then
|
2021-02-12 19:00:01 +00:00
|
|
|
rust_sysroot=~/.rustup/toolchains/"$rust_toolchain"
|
|
|
|
path_prepend path "$rust_sysroot"/bin
|
|
|
|
path_prepend fpath "$rust_sysroot"/zsh/site-functions
|
|
|
|
path_prepend manpath "$rust_sysroot"/share/man
|
2021-02-13 14:39:18 +00:00
|
|
|
path_prepend ld_library_path "$rust_sysroot"/lib
|
2021-02-13 15:31:01 +00:00
|
|
|
unset rust_sysroot
|
2021-02-12 19:00:01 +00:00
|
|
|
fi
|
2021-02-13 15:31:01 +00:00
|
|
|
|
|
|
|
unset rust_toolchain
|
2019-09-24 19:34:15 +00:00
|
|
|
fi
|
2021-02-13 15:31:01 +00:00
|
|
|
|
2021-02-12 19:00:01 +00:00
|
|
|
path_prepend path ~/.cargo/bin
|
2018-10-11 20:38:05 +00:00
|
|
|
|
2019-05-11 11:54:20 +00:00
|
|
|
# add my binaries and completions
|
2020-01-05 11:43:46 +00:00
|
|
|
path_prepend path "${ZSH_DOTFILES:h}/scripts"
|
|
|
|
path_prepend fpath "$ZSH_DOTFILES/completions"
|
2018-11-13 06:05:03 +00:00
|
|
|
|
2019-09-24 19:34:15 +00:00
|
|
|
# add user binaries
|
2020-01-05 11:43:46 +00:00
|
|
|
path_prepend path ~/.local/bin
|
|
|
|
|
|
|
|
unfunction path_prepend
|
2021-02-13 14:39:18 +00:00
|
|
|
|
|
|
|
# For some reason manpath is not always set when logging with ssh for instance.
|
|
|
|
# Let's ensure that it is always set and exported. The additional colon ensures
|
|
|
|
# that the system manpath isn't overwritten (see manpath(1)).
|
|
|
|
if [[ -n "$MANPATH" && "$MANPATH" != *: ]]; then
|
|
|
|
# Append a colon if MANPATH isn't empty and doesn't end with a colon already
|
|
|
|
MANPATH="$MANPATH:"
|
|
|
|
fi
|
|
|
|
export MANPATH="$MANPATH"
|