vinix-ports / zsh / zshrc
63 lines · 55 sloc · 2.38 KB
Raw
1# System-wide .zshrc file for zsh(1), sourced only for interactive shells.
2#
3# Global order: zshenv, zprofile, zshrc, zlogin
4
5# If ZSH startup files exist both in $HOME and XDG-based config directory,
6# print a warning (but only if running as a login shell). Note that XDG-based
7# config directory is used only when no ZSH startup files are found in $HOME
8# (see /etc/zsh/zshenv).
9if [[ -z "${ZDOTDIR-}" && -o login ]]; then
10 _xdgdir=${XDG_CONFIG_HOME:-$HOME/.config}/zsh
11 if _xdgrcs=("$_xdgdir"/.z{shenv,profile,shrc,login}(N)) && (( $#_xdgrcs )); then
12 _homercs=("$HOME"/.z{shenv,profile,shrc,login}(N:t))
13 print "Warning: Found Zsh startup files both in ~/ and ${_xdgdir/$HOME/\~}/, the latter will\n" \
14 " be ignored (tip: move $_homercs to ${_xdgdir/$HOME/\~}/)." >&2
15 fi
16 unset _xdgdir _xdgrcs _homercs
17fi
18
19# TIP: If you don't want any plugins to be automatically loaded here, add
20# `zsh_plugin_dirs=()` to your $ZDOTDIR/.zshenv.
21if (( ! ${+zsh_plugin_dirs} )); then
22 zsh_plugin_dirs=("${XDG_DATA_HOME:-$HOME/.local/share}/zsh/plugins")
23fi
24
25# TIP: If you want to automatically use all ZSH plugins installed from Alpine
26# packages, add `ZSH_LOAD_SYSTEM_PLUGINS=yes` to your $ZDOTDIR/.zshenv.
27if [[ "${ZSH_LOAD_SYSTEM_PLUGINS-}" = [1ty]* ]]; then
28 zsh_plugin_dirs+=('/usr/share/zsh/plugins')
29fi
30
31# Find plugins (per Oh-My-Zsh convention) under $zsh_plugin_dirs (array of
32# paths) and add them to $fpath.
33_plugins=()
34for _dir ($zsh_plugin_dirs); do
35 for _name ("$_dir"/*(N:t)); do # equivalent of 'basename $i'
36 if [[ -f "$_dir/$_name/$_name.plugin.zsh" ]]; then
37 _plugins+=("$_dir/$_name/$_name.plugin.zsh")
38 fpath=("$_dir/$_name" $fpath)
39 fi
40 done
41done
42
43# Source each <name>.zsh script in /etc/zsh/zshrc.d/ which <name> is not
44# included in $zshrcd_blacklist.
45#
46# TIP: If you want to prevent some scripts in /etc/zsh/zshrc.d from being
47# loaded, say a.zsh and b.zsh, add `zshrcd_blacklist=(a b)` to your
48# $ZDOTDIR/.zshenv ($XDG_CONFIG_HOME/zsh/.zshenv).
49zshrcd_blacklist+=()
50_scripts=(/etc/zsh/zshrc.d/*.zsh(N:t:r)) # equivalent of 'basename $i .zsh'
51for _name (${_scripts:|zshrcd_blacklist}); do # :| is a set difference A \ B
52 source "/etc/zsh/zshrc.d/$_name.zsh"
53done
54
55# Source all plugins found in $zsh_plugin_dirs.
56for _plugin ($_plugins); do
57 source "$_plugin"
58done
59
60unset _dir _name _plugin _plugins _scripts
61unset zsh_plugin_dirs zshrcd_blacklist ZSH_LOAD_SYSTEM_PLUGINS
62
63# vim: set ft=zsh ts=4:
64