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

Re: Ability to set HISTNO to a certain position from within zshrc



On Sep 13,  3:07pm, Felix Rosencrantz wrote:
}
} I wanted to start in the middle of history not the beginning.  So the lines
} above the starting point contain commands that might need to be run, and the
} starting line and following lines contain the likely sequence of commands to
} run.
} 
} With the "print -z"/ainh solution I lose the ability to have the leading
} commands.

So use print -z followed by history-search-backward, followed by either
moving up through the history or executing accept-line-and-down-history.

If it's really too much to have to hit one extra key before hammering away
at Enter, set up a keymap (see bindkey -N) in which up-arrow is bound to
a user-defined widget that changes back to the default keymap and then
executes history-search-backward and finally executes up-history, and in
which Enter is bound to a user-defined widget that changes back to the
default keymap and then executes accept-line-and-down-history.  Install
that keymap right after your print -z.

} It almost seems like there should be a infer-back-into-history, where it
} determines the inferred line, and jumps to it in history.

Isn't that what history-search-backward does?

} Maybe even an accept-and-down-history-or-infer, which accepts,
} attempts to go down in history, and if at the end of the history,
} attempts to infer the next command.

I think all the tools are available to write this as a user-defined widget.
As a crude stab at it:

aadhoi () {
    local buffer="$BUFFER"
    if zle down-history
    then
    	zle up-history
	BUFFER="$buffer"
	zle accept-line-and-down-history
    else
	zle -U $'\exinfer-next-history\n'
	zle accept-and-hold
    fi
}



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