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

Re: !$ changes when mistyped?

On Thu, 23 Sep 2010, Bart Schaefer wrote:

On Sep 23,  4:22pm, Benjamin R. Haskell wrote:
} Is this behavior expected -- should history expansion/completion } (terminology?) change what '!$' references? If so, is it configurable?

Quoth the documentation:

--- 8< ---
By default, a history reference with no event designator refers to the same event as any preceding history reference on that command line; if it is the only history reference in a command, it refers to the previous command. However, if the option CSH_JUNKIE_HISTORY is set, then every history reference with no event specification _always_ refers to the previous command.

For example, `!' is the event designator for the previous command, so `!!:1' always refers to the first word of the previous command, and `!!$' always refers to the last word of the previous command. With CSH_JUNKIE_HISTORY set, then `!:1' and `!$' function in the same manner as `!!:1' and `!!$', respectively. Conversely, if CSH_JUNKIE_HISTORY is unset, then `!:1' and `!$' refer to the first and last words, respectively, of the same event referenced by the nearest other history reference preceding them on the current command line, or to the previous command if there is no preceding reference.
--- 8< ---

What the doc doesn't say, but which is true, is that history references expanded by magic-space or completion are considered "the nearest other history reference preceding" for this purpose.

Hence you probably want CSH_JUNKIE_HISTORY.

Awesome.  Yes, this appears to be exactly what I was looking for.


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