-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathzshenv
63 lines (52 loc) · 2.48 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
# NOTE: Keep in mind that this file will be loaded for _every_ usage of zsh,
# either as an interactive shell or a script interpreter.
ORIGINAL_PATH=$PATH
# ------------------ shell config
# FIXME: ⚠ ⚠ This is not reproducible, should NOT load anything from ~/... ⚠ ⚠
# => We must find a way to inject cross-shell env script (or DATA)..
# (In the meantime, the following line is HARD-replaced on zdotdir pkg build with a nix store path)
source ~/.dot/shell/env.sh
ZSH_MY_CONF_DIR=~/.zsh
# ID of the config, used to seperate cache/data dirs for different zsh configs
ZSH_CONFIG_ID=main
# Dir where to store cache / volatile files
ZSH_CACHE_DIR=${XDG_CACHE_DIR:-$HOME/.cache}/zsh-${ZSH_CONFIG_ID}
# Dir where to store state files specific to $ZSH_CONFIG_ID
# (e.g. shell history, recent directories, ..)
ZSH_STATE_DIR=${XDG_STATE_DIR:-$HOME/.local/state}/zsh-${ZSH_CONFIG_ID}
# Dir where to store files shared between all configs
# (e.g. shell history, recent directories, ..)
ZSH_STATE_DIR_SHARED=${XDG_STATE_DIR:-$HOME/.local/state}/zsh-shared
# Dir where to store data files specific to $ZSH_CONFIG_ID
ZSH_DATA_DIR=${XDG_DATA_DIR:-$HOME/.local/share}/zsh-${ZSH_CONFIG_ID}
mkdir -p $ZSH_CACHE_DIR
mkdir -p $ZSH_DATA_DIR
mkdir -p $ZSH_STATE_DIR $ZSH_STATE_DIR_SHARED
# Ensure $SHELL is set to `zsh` full path
# (instead of a default like `bash` if not set at system level)
#
# NOTE(nix): $SHELL is used as the default shell in `nix shell ...`
#
# We cannot just set it to `which zsh`, because the current zsh instance might not be in PATH
# (e.g. when executed through `nix run ...`, or directly from its path)
#
# ---
#
# $ZSH_ARGZERO is either:
# - the path to zsh binary (when zsh used in interactive mode) <-- what we're interested in
# - the path to a script (when doing `zsh foo.zsh` or `./foo.zsh`)
#
# We distinguish between the two by checking $ZSH_NAME, which is always the basename of the zsh
# executable, so we can use it to compare $ZSH_ARGZERO against it.
#
# refs:
# - ZSH_NAME: https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-ZSH_005fNAME
# - ZSH_ARGZERO: https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-ZSH_005fARGZERO
if [[ $(basename "$ZSH_ARGZERO") == "$ZSH_NAME" ]]; then
export SHELL="$ZSH_ARGZERO"
else
# ZSH_ARGZERO is not the zsh instance path, it's probably the path to a script.
# Do not set $SHELL with it as that would be invalid for downstream uses of the var.
true # (if branches require a command..)
fi
true # The config should always finish well!