ftblog

:: widerstand zwecklos ::
email jabber gpgkey
hackergotchi

March 19, 2008

ctrl-x N, N element [0,9]

Filed under: computer -- 22:40

### jump behind the Nth word on the cmdline.
function jump_after_wordN() {
    setopt localoptions noksharrays extendedglob
    local words
    local -i i num=$1

    (( num == 0 )) && (( num = 10 ))
    words=(${(z)BUFFER})
    if (( ${#words} <= num )) ; then
        CURSOR=${#BUFFER}
    else
        if (( num == 1 )) ; then
            CURSOR=${#${words[${num}]}}
            return
        fi

        (( CURSOR = 1 ))
        for (( i = 1 ; i <= num ; ++i )) ; do
            (( CURSOR += ${#${words[$(( i ))]}} ))
            (( i == num )) && break

            while [[ ${BUFFER[$(( CURSOR + 1 ))]} == [[:space:]] ]] ; do
                (( CURSOR++ ))
            done
        done
    fi
}

for i in {0..9} ; do
    eval "function jump_after_word${i} () { jump_after_wordN ${i} }"
done

zle -N jump_after_wordN
for i in {0..9} ; do
    zle -N jump_after_word${i}
    bindkey '^x'${i} jump_after_word${i}
done

Siehe: ~/etc/zsh/zfunct und ~/etc/zsh/zle

Powered by zblog
valid css | valid xhtml | utf-8 encoded | best viewed with anybrowser