1
0
mirror of https://github.com/robbyrussell/oh-my-zsh.git synced 2025-12-06 07:20:40 +01:00

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>
This commit is contained in:
Marc Cornellà
2023-04-03 23:14:36 +02:00
committed by GitHub
parent f8bf88edca
commit 1ad167dfac
3 changed files with 86 additions and 19 deletions

View File

@@ -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