-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshenv
166 lines (134 loc) · 3.41 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#########################################
# Defines environment variables and global helpers.
#
# WARNING: Avoid modifying this file.
# Modify 'zshrc.local, zlogin, zlogout or zprofile' instead.
#########################################
#########################################
# Debugging helpers
#########################################
# setopt SOURCE_TRACE
# setopt XTRACE
#########################################
# Sanitize paths
#########################################
typeset -gx cdpath fpath mailpath path
typeset -gx MANPATH manpath
typeset -gx INFOPATH infopath
typeset -gx XDG_CACHE_HOME XDG_DATA_HOME XDG_CONFIG_HOME
# Bin Paths
## Set the main directories that Zsh searches for programs.
## - User paths (i.e. ~/.bin) are added again in 'zshrc' to ensure they're first.
path=(
$HOME/.bin
$HOME/.local/{bin,sbin}
/usr/local/{bin,sbin}
/usr/libexec
/usr/{bin,sbin}
/{bin,sbin}
$path
)
# CD Paths
## Set the the list of directories that cd searches.
cdpath=(
$cdpath
)
# Info Paths
## Set the list of directories that `info` searches for manuals.
infopath=(
/usr/local/share/info
/usr/share/info
$infopath
)
# Man Paths
## Set the list of directories that `man` searches for manuals.
manpath=(
/usr/local/share/man
/usr/share/man
$manpath
)
# Function Paths
## Set additional directories for ZSH to search for functions.
fpath=(
$fpath
)
#########################################
# Safer commands that check for x-istence
#########################################
# Check if we can read given files and source those we can.
function xsource() {
if (( ${#argv} < 1 )) ; then
printf 'usage: xsource FILE(s)...\n' >&2
return 1
fi
while (( ${#argv} > 0 )) ; do
[[ -r "$1" ]] && source "$1"
shift
done
return 0
}
# Check if we can read a given file and 'cat(1)' it.
function xcat() {
emulate -L zsh
if (( ${#argv} != 1 )) ; then
printf 'usage: xcat FILE\n' >&2
return 1
fi
[[ -r $1 ]] && cat $1
return 0
}
# Checks if a command exists and returns either true or false.
# Usage: xcmnd [-c|-g] word
# -c only checks for external commands
# -g does the usual tests and also checks for global aliases
function xcmd() {
emulate -L zsh
local -i command deep
if [[ $1 == '-c' ]] ; then
(( command = 1 ))
shift
elif [[ $1 == '-g' ]] ; then
(( deep = 1 ))
else
(( command = 0 ))
(( deep = 0 ))
fi
if (( ${#argv} != 1 )) ; then
printf 'usage: xcmnd [-c] <command>\n' >&2
return 1
fi
if (( command > 0 )) ; then
[[ -n ${commands[$1]} ]] && return 0
return 1
fi
if [[ -n ${commands[$1]} ]] \
|| [[ -n ${functions[$1]} ]] \
|| [[ -n ${aliases[$1]} ]] \
|| [[ -n ${reswords[(r)$1]} ]] ; then
return 0
fi
if (( gatoo > 0 )) && [[ -n ${galiases[$1]} ]] ; then
return 0
fi
return 1
}
# Check if the underlying OS is a Darwin
function xdarwin(){
[[ $OSTYPE == darwin* ]] && return 0
return 1
}
# Check if the underlying OS is a Unix
function xfreebsd(){
[[ $OSTYPE == freebsd* ]] && return 0
return 1
}
# Check if the underlying OS is a Linux
function xlinux(){
[[ $OSTYPE == linux* ]] && return 0
return 1
}
# Check if the underlying OS is a Cygwin Environment
function xlinux(){
[[ $OSTYPE == cygwin* ]] && return 0
return 1
}