-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathzshenv
122 lines (106 loc) Β· 4.84 KB
/
zshenv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
main() {
# set DOTFILES env var (statically if possible for speed, else dynamically)
if [ -d "$HOME/.files" ]; then
# to avoid unnecessary overhead assume the `$HOME/.files` directory contains
# this config if it exists
export DOTFILES="$HOME/.files"
else
dynamically_determine_dotfiles # see function at end of file
fi
dynamically_set_homebrew_prefix # see function below
# XDG directory specification
# ref - https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"
# << homebrew >>
# ref - https://github.com/Homebrew/brew/blob/master/docs/Manpage.md#environment
export HOMEBREW_INSTALL_CLEANUP=0 # checking existence, not value
export HOMEBREW_AUTO_UPDATE_SECS=86400 # check for update every 24 hours
# << tmuxinator >>
# ref - https://github.com/tmuxinator/tmuxinator#project-configuration-location
export TMUXINATOR_CONFIG="$DOTFILES/tmux/tmuxinator_configs"
# prevent generation of .pyc files
export PYTHONDONTWRITEBYTECODE=1
export BAT_CONFIG_PATH="$DOTFILES/utilities/bat/bat.conf"
export DIRENV_LOG_FORMAT= # silence direnv
# output ANSI "color" escape sequences
# value of LESS is passed to `less` as args
export LESS=" -R"
# colored paging (enables colored man pages)
# ref - https://github.com/sorin-ionescu/prezto/blob/cfeb8cd6c9f60c2a928f4c706d0137c7de2ef106/modules/environment/init.zsh#L59-L67
export LESS_TERMCAP_mb=$'\E[01;31m' # begins blinking
export LESS_TERMCAP_md=$'\E[01;31m' # begins bold
export LESS_TERMCAP_me=$'\E[0m' # ends mode
export LESS_TERMCAP_se=$'\E[0m' # ends standout-mode
export LESS_TERMCAP_so=$'\E[00;47;30m' # begins standout-mode
export LESS_TERMCAP_ue=$'\E[0m' # ends underline
export LESS_TERMCAP_us=$'\E[01;32m' # begins underline
# << work-specific >>
[ -d "$HOME/work" ] && {
export GOPATH="$HOME/work/go"
export VAULT_ADDR=https://vault.services.opendoor.com:8200
export ANDROID_HOME="$HOME/Library/Android/sdk" # for android studio
export OD_CURRENT_USER_EMAIL="[email protected]"
}
# << end work-specific >>
}
# `brew --prefix` takes ~25-40ms on my machine vs ~11ms for the if/else below
# to avoid that overhead I hardcode the path based on the existence of a folder
# in the expected installation locations across OSes (these locations seem
# unlikely to change soon)
#
# to see times on your machine (you may have to `brew install hyperfine`):
# - `hyperfine 'brew --prefix'`
# - `hyperfine ./foo.sh` where `foo.sh` is a script w/ the if/else below
dynamically_set_homebrew_prefix() {
local macos_installation linux_sudo_installation linux_no_sudo_installation
local calculated_installation
macos_brew_installation='/usr/local'
linux_sudo_installation='/home/linuxbrew/.linuxbrew'
linux_no_sudo_installation="$HOME/.linuxbrew"
# on macOS the installation location `/usr/local` exists regardless of whether
# `brew` is installed so we need to check the inner Homebrew folder
if [ -d "$macos_brew_installation/Homebrew" ]; then
calculated_installation="$macos_brew_installation"
elif [ -d "$linux_sudo_installation" ]; then
calculated_installation="$linux_sudo_installation"
elif [ -d "$linux_no_sudo_installation" ]; then
calculated_installation="$linux_no_sudo_installation"
fi
# `calculated_installation` will be set if Homebrew is installed to any of the
# above locations
[ -z "$calculated_installation" ] || {
export HOMEBREW_PREFIX="$calculated_installation"
}
}
# dynamically determine path to `.files` repo
# attempts to follow symlinked `zshenv` (bails if `zshenv` is not symlinked)
dynamically_determine_dotfiles() {
local follow_symlink_command path_to_symlinked_zshenv path_to_zshenv
# path to this script, likely `$HOME/.zshenv` (this does NOT follow symlinks)
# ref - https://stackoverflow.com/a/23259585
path_to_zshenv="${(%):-%x}"
# if it isn't a symlink bail, requires manual configuration
[ -L "$path_to_zshenv" ] || {
echo 'Failed to determine $DOTFILES as this script is not symlinked'
exit 1
}
# follow symlink - https://stackoverflow.com/a/42918
if command -v realpath > /dev/null; then
follow_symlink_command="realpath"
elif command -v readlink > /dev/null; then
if [ "$(uname)" = "Darwin" ]; then
follow_symlink_command="readlink" # macOS
else
follow_symlink_command="readlink -f" # linux implementations require `-f`
fi
else
echo 'Failed to find command to follow symlinks'
exit 1
fi
path_to_symlinked_zshenv="$("$follow_symlink_command" "$path_to_zshenv")"
# `:h` removes path component from end, `:h:h` to remove `zsh/zshenv` (`zsh` & `zshenv`)
# ref - http://zsh.sourceforge.net/Doc/Release/Expansion.html#Modifiers
export DOTFILES="${path_to_symlinked_zshenv:h:h}"
}
main "$@"