Bernhard Tittelbach wrote:
> after using sudo-command-line, the CL-length will have increased by 5 chars. As
> the cursor position stays the same, this amounts to a cursor offset with respect
> to my typed test of 5 chars to the left.
>
> please increase CURSOR position by 5 chars (==strlen "sudo "), so cursorposition
> remains the same, relative to typed test
>
> proposal:
>
> sudo-command-line() {
> [[ -z $BUFFER ]] && zle up-history
> [[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER" && CURSOR=$((CURSOR+5))
> }
Good point. I'd like to have the code look a little clearer
though. Lengthy "... && ... && ..." chains are fine as one shot command
lines, but are not useful in real code. Thus:
sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history
if [[ $BUFFER != sudo\ * ]]; then
BUFFER="sudo $BUFFER"
CURSOR=$(( CURSOR+5 ))
fi
}
Objections?
Regards, Frank |