-
Notifications
You must be signed in to change notification settings - Fork 8
/
zshenv
94 lines (80 loc) · 3.74 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
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
"$DOTFILES/infra/scripts/component_enabled.sh" 'zsh' || return 0
# 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"
# prevent generation of .pyc files
export PYTHONDONTWRITEBYTECODE=1
export DIRENV_LOG_FORMAT= # silence direnv
# set default pager
# - `--no-init` - leaves output on screen instead of clearing
# - `--quit-if-one-screen` - behaves as if there were no pager if output fits
# - `--raw-control-characters` - render control characrers correctly (https://unix.stackexchange.com/a/280420)
export PAGER="less --no-init --quit-if-one-screen --raw-control-chars"
# 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
dynamically_set_lscolors
}
# colors to use when highlighting `ls` output
dynamically_set_lscolors() {
export CLICOLOR=1 # enable colors at all
if command -v vivid > /dev/null; then
# TODO: use one-dark theme added in https://github.com/sharkdp/vivid/pull/51
# whenever a new release is cut - https://github.com/sharkdp/vivid/releases
export LS_COLORS="$(vivid generate snazzy)"
else
# https://geoff.greer.fm/lscolors/
export LS_COLORS="di=34:ln=35:so=36:pi=31:ex=32:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43";
fi
# Note: BSD `ls` (which is the default on macOS) uses `LSCOLORS` instead of
# `LS_COLORS`. Add `LSCOLORS` (generated from the same
# https://geoff.greer.fm/lscolors/) as a fallback for any BSD `ls` usage
export LSCOLORS="exfxgxbxcxegedabagacad"
}
# 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 "$@"