Created
January 29, 2012 03:33
-
-
Save matthewd/1697002 to your computer and use it in GitHub Desktop.
Check for unused aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
check_an_alias() { | |
alias_name="$1" | |
typed_cmd=(${(zQ)2}) | |
alias_result=(${(zQ)3}) | |
while [[ "${alias_result[1]}" = "noglob" ]] || [[ "${alias_result[1]}" = "nocorrect" ]]; do | |
shift alias_result | |
done | |
if [[ "${#alias_result}" -gt "${#typed_cmd}" ]]; then | |
return 1 | |
fi | |
while [[ "${#alias_result}" -gt 0 ]]; do | |
if [[ "${alias_result[1]}" != "${typed_cmd[1]}" ]]; then | |
return 1 | |
fi | |
shift alias_result typed_cmd | |
done | |
return 0 | |
} | |
check_for_aliases() { | |
alias -r | while IFS='=' read alias_name alias_result; do | |
if [[ "${#alias_name}" -lt "${#alias_result}" ]]; then | |
output_result="$alias_result" | |
if check_an_alias "$alias_name" "$1" "$alias_result"; then | |
( | |
echo "${fg_bold[magenta]}What are you, looking for RSI?!?${reset_color}" | |
echo " ${fg_no_bold[green]}${alias_name}${reset_color}=${fg_no_bold[red]}${output_result}${reset_color}" | |
echo | |
) >&2 | |
fi | |
fi | |
done | |
} | |
autoload colors; colors | |
add-zsh-hook preexec check_for_aliases |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment