diff options
author | Marc Cornellà <hello@mcornella.com> | 2023-04-03 23:14:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 23:14:36 +0200 |
commit | 1ad167dfac325a9f92e0693c70d0ab3f7c4c574b (patch) | |
tree | 9974db114a4f188a48bd0bde557fcf3704119052 /oh-my-zsh.sh | |
parent | f8bf88edca7a3246e065f13cefac2c5f1ab396e0 (diff) | |
download | zsh-1ad167dfac325a9f92e0693c70d0ab3f7c4c574b.tar.gz zsh-1ad167dfac325a9f92e0693c70d0ab3f7c4c574b.tar.bz2 zsh-1ad167dfac325a9f92e0693c70d0ab3f7c4c574b.zip |
feat(init)!: allow turning off aliases for libs and plugins (#11550)
BREAKING CHANGE: the previous zstyle setting to disable `lib/directories.zsh` aliases has
been changed to the new syntax: `zstyle ':omz:lib:directories' aliases no`. See
https://github.com/ohmyzsh/ohmyzsh#skip-aliases to see other ways you can use this setting.
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
Diffstat (limited to 'oh-my-zsh.sh')
-rw-r--r-- | oh-my-zsh.sh | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 363cfca8b..20d2e354c 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -146,22 +146,51 @@ if command mkdir "${ZSH_COMPDUMP}.lock" 2>/dev/null; then command rm -rf "$ZSH_COMPDUMP.zwc.old" "${ZSH_COMPDUMP}.lock" fi +_omz_source() { + local context filepath="$1" + + # Construct zstyle context based on path + case "$filepath" in + lib/*) context="lib:${filepath:t:r}" ;; # :t = lib_name.zsh, :r = lib_name + plugins/*) context="plugins:${filepath:h2:t}" ;; # :h2 = plugins/plugin_name, :t = plugin_name + esac + + local disable_aliases=0 + zstyle -T ":omz:${context}" aliases || disable_aliases=1 + + # Back up alias names prior to sourcing + local -a aliases_pre galiases_pre + if (( disable_aliases )); then + aliases_pre=("${(@k)aliases}") + galiases_pre=("${(@k)galiases}") + fi + + # Source file from $ZSH_CUSTOM if it exists, otherwise from $ZSH + if [[ -f "$ZSH_CUSTOM/$filepath" ]]; then + source "$ZSH_CUSTOM/$filepath" + elif [[ -f "$ZSH/$filepath" ]]; then + source "$ZSH/$filepath" + fi + + # Unset all aliases that don't appear in the backed up list of aliases + if (( disable_aliases )); then + local -a disabled + # ${var:|array} gets the list of items in var not in array + disabled=("${(@k)aliases:|aliases_pre}" "${(@k)galiases:|galiases_pre}") + (( $#disabled == 0 )) || unalias "${(@)disabled}" + fi +} + # Load all of the config files in ~/oh-my-zsh that end in .zsh # TIP: Add files you don't want in git to .gitignore for config_file ("$ZSH"/lib/*.zsh); do - custom_config_file="$ZSH_CUSTOM/lib/${config_file:t}" - [[ -f "$custom_config_file" ]] && config_file="$custom_config_file" - source "$config_file" + _omz_source "${config_file:t2}" done unset custom_config_file # Load all of the plugins that were defined in ~/.zshrc for plugin ($plugins); do - if [[ -f "$ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh" ]]; then - source "$ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh" - elif [[ -f "$ZSH/plugins/$plugin/$plugin.plugin.zsh" ]]; then - source "$ZSH/plugins/$plugin/$plugin.plugin.zsh" - fi + _omz_source "plugins/$plugin/$plugin.plugin.zsh" done unset plugin |