[Home] Zsh logo

dot.zshenv

Zsh Wizard

Download dot.zshenv Return to Examples
  1. ########################################
  2. #
  3. # .zshenv: zsh environment settings
  4. # Written by Deborah Pickett <debbiep@csse.monash.edu.au>
  5. # with large wads taken from others.
  6. #
  7. ########################################
  8. # Since .zshenv is sourced for every invocation of zsh, it is vital that
  9. # it run quickly. Only environment variables that must be set for
  10. # a noninteractive shell are set here. If external commands must be run
  11. # here they are kept to a bare minimum and exported shell variables
  12. # remember the results to keep them from needing to be run again.
  13. ###############
  14. # zsh functions
  15. # Most functions are auto-loaded later on, but some are defined
  16. # explicitly since they're needed by the startup files and would
  17. # automatically be loaded in any case.
  18. # rationalize-path()
  19. # Later we'll need to trim down the paths that follow because the ones
  20. # given here are for all my accounts, some of which have unusual
  21. # paths in them. rationalize-path will remove
  22. # nonexistent directories from an array.
  23. rationalize-path () {
  24. # Note that this works only on arrays, not colon-delimited strings.
  25. # Not that this is a problem now that there is typeset -T.
  26. local element
  27. local build
  28. build=()
  29. # Evil quoting to survive an eval and to make sure that
  30. # this works even with variables containing IFS characters, if I'm
  31. # crazy enough to setopt shwordsplit.
  32. eval '
  33. foreach element in "$'"$1"'[@]"
  34. do
  35. if [[ -d "$element" ]]
  36. then
  37. build=("$build[@]" "$element")
  38. fi
  39. done
  40. '"$1"'=( "$build[@]" )
  41. '
  42. }
  43. # zsh-version
  44. # Return true (0) if the running version of ZSH is equal to
  45. # or more recent than the one requested. I need this because of all the
  46. # bleeding-edge zsh features I use here. :) Cache the results for
  47. # speed, if associative arrays are available.
  48. # The zsh distribution comes with the is-at-least function to do the
  49. # same job, but I'd already written this before I found that out. :)
  50. zsh-version ()
  51. {
  52. # If this result is cached . .
  53. if [[ ${+zshversioncache} -eq 1 && ${+zshversioncache[$1]} -eq 1 ]]
  54. then
  55. return $zshversioncache[$1]
  56. fi
  57. local running
  58. local wanted
  59. # Split the things to compare into two arrays.
  60. running=(${(s:.:)ZSH_VERSION})
  61. wanted=(${(s:.:)1})
  62. # Compare parts until we have an answer.
  63. while [[ $#running -gt 0 ]]
  64. do
  65. # Now compare each first part.
  66. if [[ $running[1] -lt $wanted[1] ]]
  67. then
  68. if [[ ${+zshversioncache} -eq 1 ]]
  69. then
  70. zshversioncache[$1]=1
  71. fi
  72. return 1 # Failure, want more recent than we have
  73. elif [[ $running[1] -gt $wanted[1] ]]
  74. then
  75. if [[ ${+zshversioncache} -eq 1 ]]
  76. then
  77. zshversioncache[$1]=0
  78. fi
  79. return 0 # Success, running newer version
  80. else
  81. shift running # Look at next part of version
  82. shift wanted
  83. fi
  84. done
  85. if [[ $#wanted -gt 0 ]]
  86. then
  87. if [[ ${+zshversioncache} -eq 1 ]]
  88. then
  89. zshversioncache[$1]=1
  90. fi
  91. return 1 # Failure, wanted version has an extra part and is thus later
  92. else
  93. if [[ ${+zshversioncache} -eq 1 ]]
  94. then
  95. zshversioncache[$1]=0
  96. fi
  97. return 0 # Exactly the same version
  98. fi
  99. }
  100. if zsh-version 3.1.6
  101. then
  102. # Associative arrays are available.
  103. typeset -A zshversioncache
  104. zshversioncache=( )
  105. fi
  106. ###############
  107. # Shell options
  108. # These are the options that apply to noninteractive shells.
  109. # Ones in capitals are variations from the default ZSH behaviour.
  110. setopt \
  111. no_allexport \
  112. badpattern \
  113. no_bsdecho \
  114. no_chaselinks \
  115. NO_CLOBBER \
  116. no_cshjunkieloops \
  117. no_cshjunkiequotes \
  118. no_cshnullglob \
  119. equals \
  120. no_errexit \
  121. exec \
  122. EXTENDEDGLOB \
  123. functionargzero \
  124. glob \
  125. no_globassign \
  126. GLOBDOTS \
  127. no_globsubst \
  128. hashcmds \
  129. hashdirs \
  130. no_ignorebraces \
  131. no_ksharrays \
  132. no_localoptions \
  133. no_magicequalsubst \
  134. no_markdirs \
  135. multios \
  136. nomatch \
  137. no_nullglob \
  138. NUMERICGLOBSORT \
  139. no_pathdirs \
  140. no_posixbuiltins \
  141. no_printexitvalue \
  142. PUSHDIGNOREDUPS \
  143. PUSHDMINUS \
  144. PUSHDSILENT \
  145. PUSHDTOHOME \
  146. no_rcexpandparam \
  147. no_rcquotes \
  148. rcs \
  149. no_shfileexpansion \
  150. no_shglob \
  151. no_shoptionletters \
  152. shortloops \
  153. no_shwordsplit \
  154. unset
  155. if zsh-version 3.0.6
  156. then
  157. setopt \
  158. bareglobqual \
  159. no_kshautoload \
  160. no_kshglob \
  161. no_printeightbit \
  162. no_restricted
  163. fi
  164. if zsh-version 3.1.6
  165. then
  166. setopt \
  167. no_chasedots \
  168. globalrcs \
  169. no_localtraps
  170. fi
  171. if zsh-version 3.1.8
  172. then
  173. setopt \
  174. no_cshnullcmd \
  175. NO_GLOBALEXPORT \
  176. no_octalzeroes \
  177. no_shnullcmd
  178. fi
  179. ###############
  180. # Paths for zsh
  181. # Path for cd to search; used to need to explicitly set "." for the cdmatch
  182. # function (and retained for backward compatibility).
  183. cdpath=( . )
  184. export CDPATH
  185. # Only unique entries please.
  186. typeset -U cdpath
  187. # Path to search for autoloadable functions.
  188. fpath=( $HOME/lib/zsh/func "$fpath[@]" )
  189. export FPATH
  190. # Only unique entries please.
  191. typeset -U fpath
  192. # Include function path in script path so that we can run them even
  193. # though a subshell may not know about functions.
  194. # PATH should already be exported, but in case not. . .
  195. path=(
  196. "$HOME/bin/$MACHTYPE-$OSTYPE"
  197. "$HOME/bin"
  198. /usr/local/bin
  199. /usr/local/sbin
  200. /usr/local/etc
  201. /sbin
  202. /etc
  203. /bin
  204. /usr/bin
  205. /usr/sbin
  206. /usr/ucb
  207. /usr/bsd
  208. /usr/X11/bin
  209. /usr/bin/X11
  210. /usr/local/X11/bin
  211. /usr/monash/X11/bin
  212. /usr/monash/bin
  213. /usr/monash/etc
  214. /usr/monash/gnu/bin
  215. /usr/monash/contrib/bin
  216. /usr/monash/contrib/etc
  217. /usr/monash/contrib/X11/bin
  218. /usr/local/contrib/lib/kde/bin
  219. /usr/local/tex/bin
  220. /usr/local/lib/zsh/scr
  221. /usr/monash/contrib/games
  222. /usr/local/games
  223. /usr/monash/games
  224. /usr/games
  225. "$path[@]"
  226. "$fpath[@]"
  227. )
  228. export PATH
  229. # Only unique entries please.
  230. typeset -U path
  231. # Remove entries that don't exist on this system. Just for sanity's
  232. # sake more than anything.
  233. rationalize-path path
  234. # My mail folders
  235. mailpath=(
  236. "/usr/spool/mail/$LOGNAME?You inexplicably have new mail in /usr/spool/mail/$LOGNAME"
  237. "$HOME/Mail/inbox?You have new mail in ~/Mail/inbox"
  238. "$HOME/Mail/junk?You have junk mail in ~/Mail/junk"
  239. "$HOME/Mail/uni?You have university mail in ~/Mail/uni"
  240. "$HOME/Mail/fdcmuck?You have FDCMuck mail in ~/Mail/fdcmuck"
  241. "$HOME/Mail/mermaid?You have mermaid-list mail in ~/Mail/mermaid"
  242. "$HOME/Mail/moderators?You have moderators-list mail in ~/Mail/moderators"
  243. "$HOME/Mail/picture?You have picture-list mail in ~/Mail/picture"
  244. "$HOME/Mail/life-l?You have life-list mail in ~/Mail/life-l"
  245. "$HOME/Mail/murp-l?You have murp-list mail in ~/Mail/murp-l"
  246. "$HOME/Mail/zsh?You have zsh mail in ~/Mail/zsh"
  247. "$HOME/Mail/billabong?You have billabong mail in ~/Mail/billabong"
  248. "$HOME/Mail/dryland?You have dryland mail in ~/Mail/dryland"
  249. "$HOME/Mail/fdcoz?You have FDCoz mail in ~/Mail/fdcoz"
  250. "$HOME/Mail/ldl?You have linux-dell-laptops mail in ~/Mail/ldl"
  251. )
  252. export MAILPATH
  253. ######################
  254. # functions, continued
  255. # Now that FPATH is set correctly, do autoloaded functions.
  256. # autoload all functions in $FPATH - that is, all files in
  257. # each component of the array $fpath. If there are none, feed the list
  258. # it prints into /dev/null.
  259. for paths in "$fpath[@]"
  260. do
  261. # -U switch is more recent.
  262. if zsh-version 3.1.6
  263. then
  264. autoload -U "$paths"/*(N:t) >/dev/null
  265. else
  266. autoload "$paths"/*(N:t) >/dev/null
  267. fi
  268. done
  269. unset paths
  270. #################
  271. # zsh environment
  272. # The mail folder my mail clients default to.
  273. export MAIL="$HOME/Mail/inbox"
  274. # Command to use when redirecting from/to a null command.
  275. # READNULLCMD is redefined in .zshrc for interactive shells.
  276. READNULLCMD=cat
  277. NULLCMD=cat
  278. # Size of the directory stack (pushd et al)
  279. DIRSTACKSIZE=12
  280. # Size of history list
  281. HISTSIZE=200
  282. # Unix groups: remember the original group ID. (For prompts.)
  283. if [[ ${+ORIGGID} -eq 0 ]]
  284. then
  285. export ORIGGID="$GID"
  286. fi
  287. ######################################
  288. # Other programs' environment settings
  289. # MANPATH: path for the man command to search.
  290. # Look at the manpath command's output and prepend
  291. # my own manual paths manually (ahem).
  292. if [[ ${+MANPATH} -eq 0 ]]
  293. then
  294. # Only do this if the MANPATH variable isn't already set.
  295. if whence manpath >/dev/null 2>&1
  296. then
  297. # Get the original manpath, then modify it.
  298. MANPATH="`manpath`"
  299. manpath=(
  300. "$HOME/man"
  301. "$manpath[@]"
  302. )
  303. else
  304. # This list is out of date, but it will suffice.
  305. manpath=(
  306. "$HOME/man"
  307. /usr/monash/contrib/man
  308. /usr/monash/gnu/man
  309. /usr/local/man
  310. /usr/monash/man
  311. /usr/man
  312. /usr/man/preformat
  313. /usr/X11/man
  314. /use/openwin/man
  315. /usr/monash/tex/man
  316. )
  317. rationalize-path manpath
  318. fi
  319. # And, as always, no duplicate entries are needed.
  320. typeset -U manpath
  321. export MANPATH
  322. fi
  323. # Path for info, the Anti-man(tm), to search.
  324. export INFOPATH=/usr/monash/contrib/info:/usr/local/info:/usr/monash/info:\
  325. /usr/info:/usr/emacs/info:.
  326. # Do the usual path-y things. The lowercase array one isn't used by the
  327. # info command, but it helps us to rationalize-path it.
  328. if zsh-version 3.1.6
  329. then
  330. typeset -T INFOPATH infopath
  331. rationalize-path infopath
  332. typeset -U infopath
  333. fi
  334. # Path to Qt, needed for KDE.
  335. export QTDIR=/usr/monash/contrib/lib/qt
  336. # Path for dynamic loading of libraries.
  337. export LD_LIBRARY_PATH=/usr/monash/contrib/lib:\
  338. /usr/monash/contrib/lib/qt/lib:\
  339. /usr/monash/contrib/lib/kde/lib:\
  340. "$HOME/lib/$MACHTYPE-$OSTYPE"
  341. # Do the usual path-y things. The lowercase array one isn't used by the
  342. # system, but it helps us to rationalize-path it.
  343. if zsh-version 3.1.6
  344. then
  345. typeset -T LD_LIBRARY_PATH ld_library_path
  346. rationalize-path ld_library_path
  347. typeset -U ld_library_path
  348. fi
  349. # less options.
  350. if [[ ${+LESS} -eq 0 ]]
  351. then
  352. export LESS='-deiq'
  353. # Underline non-printable characters and print them in hex
  354. # inside square brackets.
  355. export LESSBINFMT='*u[%X]'
  356. export LESSCHARSET=latin1
  357. fi
  358. # default pager
  359. if [[ ${+PAGER} -eq 0 ]]
  360. then
  361. if whence less >/dev/null 2>&1
  362. then
  363. export PAGER="`whence less`"
  364. fi
  365. fi
  366. # default editor
  367. if [[ ${+EDITOR} -eq 0 ]]
  368. then
  369. if whence vim >/dev/null 2>&1
  370. then
  371. export EDITOR="`whence vim`"
  372. fi
  373. fi
  374. # perl
  375. # Search these places for perl include files. Other paths are hopefully
  376. # configured properly already.
  377. export PERL5LIB="$HOME/lib/perl5:$HOME/lib/perl5/site_perl"
  378. # NNTP server for news
  379. export NNTPSERVER=newsserver.cc.monash.edu.au
  380. # ispell
  381. export WORDLIST="$HOME/.ispell_words"
  382. # goofey
  383. # Goofey is a chat-style program used at Monash University. It predates
  384. # ICQ and other newfangled notions by several years. I don't always use
  385. # it, since it requires a fairly reliable net connection.
  386. # If there is a file ~/.usegoofey then we'll try to use goofey on this
  387. # system. Otherwise we'll pretend it doesn't exist and skip all
  388. # related things in startup files and periodic checks.
  389. if [[ ${+USE_GOOFEY} -eq 0 && ${+NO_USE_GOOFEY} -eq 0 && -f $HOME/.usegoofey ]]
  390. then
  391. # note goofey is being used
  392. export USE_GOOFEY=1
  393. #export GOOFEYUSER=debbie
  394. else
  395. # note that it isn't being used.
  396. export NO_USE_GOOFEY=
  397. fi
  398. # Note that we're now running under a ZSH, so that future subshells can
  399. # skip some of these steps if they want. (Not that this is used at the
  400. # moment, but it's there in case I do want to do it.)
  401. export UNDERZSH=$$