Aliases are expanded at a very early stage, before a simple command is understood as such let alone a function is executed, so that can't work.
You need the
expandalias is the
bash option) option to be in effect before the command line is read and parsed.
However, if you want to disable only normal aliases, that is the ones expanded in command position defined with
alias foo=bar, doing:
is enough, because if there's an alias for
cmd, it wouldn't be expanded in:
noalias cmd args
cmd is not in command position.
That wouldn't work for global aliases though (the ones set with
alias -g, like
alias -g args=foo than expand any shell word whether they are in command position or not).
Even if you did:
setopt localoptions noaliases
And invoke your command with:
noalias 'cmd args'
That would not be foolproof, for instance after:
alias -g "'cmd arg'=gotcha"
alias -g noalias=gotcha
You'd need to run
set +o expandalias
Before the command is read. You could do it with a key binding though:
if [[ -o aliases ]]; then
set +o aliases
set -o aliases
zle -N toggle-aliases
bindkey '\eA' toggle-aliases
PS1='[aliases $options[aliases]] '$PS1
And press Alt+Shift+A to toggle.