[issue980] make sudo-command-line() restore cursor position

Frank Terbeck bts at bts.grml.org
Tue Apr 19 23:02:21 CEST 2011


Frank Terbeck <ft at grml.org> added the comment:

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

----------
assignedto: ft
messages: 3732, 3733
nosy: btittelbach, ft
priority: feature
status: chatting
title: make sudo-command-line() restore cursor position
topic: zsh

_____________________________________
GRML issue tracker <bts at bts.grml.org>
<http://bts.grml.org/grml/issue980>
_____________________________________


More information about the Bugs-changes mailing list