Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: append to history entry?
On Dec 27, 4:57pm, Ray Andrews wrote:
} Subject: Re: append to history entry?
}
} It's all this backslash and 'is it one string or several strings'
} stuff.
The "one or several" distinction of course has to do with the way
arguments are processed. You definitely want to be able to preserve
inside the function whatever argument division was supplied to it
at the call, so you need a way to indicate that; you just have to
be sure you're only making that indication when you mean it.
} ... it seems that the backslashes need protecting and reprotecting and
} yet more protecting and each stage of the protection is different from
} the last.
The backslash stuff is borrowed conceptually from C (\t for tab, etc.).
Having that same paradigm applied at multiple levels of processing stems
from the language being interpreted rather than compiled.
} For me, the task is to see the 'naturalness' for lack of a better word
} of the way that zsh does this:
}
} print -rS -- "rap ${${(q+)@}}; : ${(q-)HOST}"
The point is that this isn't "natural," because what you asked for isn't
natural. Think through what you said you want:
1. Take a command line and parse it.
2. When the parsed arguments are received by the command ...
a. reconstitute the original command line
b. append another command that includes the host name
3. Put all of that into the history, formatted such that
a. it shows what you want when you recall the history, and
b. it executes again without errors
Which step of that after the first one is "natural" for the shell?
Of course you can fudge any one of those steps. The host name most
probably doesn't have any special characters, so ${(q-)HOST} is
likely going overboard and all you really need is $HOST; but for the
sake of everyone else who's going to see this and copy-paste, it
may be worth forestopping any future problems.
Similarly you may never have any quoted spaces or backslashes or
anything like that in the arguments of "rap" and therefore ${(q+)@}
might also be unnecessary, but someone might try to use this same
recipe for some other command that does have those things. I tend
to want those people to make their own mistakes and come back with
more questions; Daniel tries to cover all corner cases up front.
} Couldn't we just:
}
} setopt protect-backslashes-thanks
} print -S "rap $@; : $HOST"
That still wouldn't work because $@ is the way you preserve argument
divisions. You can't get away from thinking about what you mean.
} Bart and Daniel didn't get it exactly right the first time. What hope
} do I have?
Stop worrying about getting it exactly right. What you had in the
first place was going to work in 90%+ of cases, and when you found
a case that didn't, then someone could have explained why not.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author