-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.zshrc
More file actions
76 lines (65 loc) · 2.02 KB
/
.zshrc
File metadata and controls
76 lines (65 loc) · 2.02 KB
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
# ---- displayed on line running command ---- #
PS1='%n@%m %~$ '
# ---- xdg base directory ---- #
# ---- https://wiki.archlinux.org/title/XDG_Base_Directory ---- #
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}" # configuration data
export XDG_DATA_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}" # data that should persist between restarts
export XDG_STATE_HOME="${XDG_STATE_HOME:-${HOME}/.local/state}" # data that is not important or portable enough
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-${HOME}/.cache}" # non-essential cached data
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}" # non-essential runtime and other data
# ---- utility functions ---- #
# ---- written longer for debugging ---- #
has() {
if command -v "${1}" > /dev/null; then
return 0
else
return 1
fi
}
safe_directory() {
if [[ -n "${1}" && ! -d "${1}" ]]; then
mkdir -p "${1}"
fi
}
safe_source() {
if [[ -f "${1}" ]]; then
source "${1}"
fi
}
is_personal() {
[[ "${USER}" == "vlad" || $(uname -o) == "Android" ]]
}
time_cmd() {
local name="${1}"
shift
if [[ -o interactive ]] && has "gdate"; then
local t1=$(gdate +%s%3N)
"$@"
local t2=$(gdate +%s%3N)
echo "${name} time: $((t2 - t1))ms"
else
"$@"
fi
}
# ---- history configuration ---- #
# ---- man zshoptions ---- #
zsh_state_home="${XDG_STATE_HOME}/zsh"
safe_directory "${zsh_state_home}"
HISTSIZE=8000 # history kept in memory
SAVEHIST=5000 # history saved to file
HISTFILE="${zsh_state_home}/history"
setopt append_history
setopt inc_append_history
setopt share_history
# ---- workspace configuration ---- #
export WORKSPACE="${HOME}/dev/repos/personal"
if ! is_personal; then
export WORKSPACE="${HOME}/dev/repos/work"
fi
# ---- source all shell configurations ---- #
shell_init() {
for source_file in "${XDG_CONFIG_HOME}"/zsh/*.zsh; do
safe_source "${source_file}"
done
}
time_cmd "init" shell_init