expand-alias-and-space() {zle _expand_alias # Expand the alias under the cursorzle magic-space # Insert a space and perform history expansion}
zle -N expand-alias-and-space
bindkey ' ' expand-alias-and-space
On 2026-04-04 15:30, Mark J. Reed wrote:
> It's not "losing the backslash". There is no backslash. The backslash
> tells the shell that the space is literal.
I know. The problem is that the need to indicate the hard space
remains. As the command tail is passed to another function, the need
for that reminder must be retained. It's a deep problem -- soft vs.
hard spaces. If the shell used '\ ' to insert some character that was
an explicitly hard space, then of course the problem would vanish, the
backslash would only be needed the one time and the hard space would
remain hard. But without the backslash of course it 'reverts' to being
a soft space.
> So if you want access to the specific way the command is typed, you
> use a normal function or script; by the time it's executed it's too
> late.You need to hook into the completion or editing (ZLE) functionality.
Yeah, I'd sure like to know how to do that. As I mentioned a while back
that code accessing $BUFFER sounded like the right place to look, but
it's way above my pay grade.