Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: psychiatric help



Have you considered a simpler solution? If I understand your goal I think this will work for you: bind the space bar to a ZLE function that expands the alias you just typed in-place. That way you get the whole expanded command right there at the prompt where you can edit it as needed, and the whole thing will automatically be what's saved in your history when you execute it.

expand-alias-and-space() {
  zle _expand_alias    # Expand the alias under the cursor
  zle magic-space       # Insert a space and perform history expansion
}

zle -N expand-alias-and-space

bindkey ' ' expand-alias-and-space
    


On Sat, Apr 4, 2026 at 6:50 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:


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.




--
Mark J. Reed <markjreed@xxxxxxxxx>


Messages sorted by: Reverse Date, Date, Thread, Author