Skip to content

Instantly share code, notes, and snippets.

@e-roux
Last active October 3, 2020 11:13
Show Gist options
  • Save e-roux/e85f7d44fc3d9bbd453157da2e24fa55 to your computer and use it in GitHub Desktop.
Save e-roux/e85f7d44fc3d9bbd453157da2e24fa55 to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
hooks=(chpwd periodic precmd preexec zshaddhistory zshexit)
for hook in $hooks; do
# First eval the hook function, stored as string
eval "hook_func_str=$\"${hook}_functions\""
# [expansion rule](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Rules)
# [Parameter expansion flags](http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags)
eval "hookfunc=\"${hook_func_str}\""
# Make an array out of the string
hookfunc=( ${(s/ /)${hookfunc}} )
# print ${(t)hookfunc}, $#hookfunc, $hookfunc[1]
# Print only the non empty arrays
if [ $#hookfunc != 0 ]; then
echo $hook
for fun in $=hookfunc; do
print "| $fun"
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment