Le 18/02/2011 18:34, Patrick Pippen a écrit :

How do I enable command and file name completion? I've tried
M-*,  M-ESC,&  ^I tab. All I keep getting is: just a blank space,
  I believe I'm missing something.

Hi,

some years later, I've written a keybind function based on the simple one found at http://www.kornshell.org/examples/keybind

my solution only works in emacs mode.
dtksh (old ksh93) and cygwin ksh93 have special handling.
don't ask how it works, I don't remember but use it on a day basis.

I call it .ksh93rc and source it using the following sentence :

[[ ${SECONDS} = *[.,]* ]] && . ./.ksh93rc

from $ENV which point on a common ksh88 and ksh93 .kshrc.

tab-tab list possible completions, esc-# tab complete w/ the # entry, works on command and arguments, arrow keys, home, end, etc.

another implementation exists here :

http://groups.google.fr/groups?num=10&hl=fr&client=firefox-a&hs=Ypw&rls=org.mozilla:fr:official&q=bindkey+1998+Brian+Hiles&um=1&ie=UTF-8&sa=N&tab=wg

Regards,

Cyrille Lefevre
--
mailto:[email protected]
#!/bin/echo error: only source
#ident @(#) $Header: /package/cvs/exploitation/util/san/libksh/Attic/ksh93rc,v 
1.1.2.5 2007/02/19 17:54:56 cle Exp $
# [[ ${SECONDS} = *[.,]* ]] && . ./.ksh93rc

{
comp=(
        tab=$'\t'
        list=$'\E='
        comp=$'\E\E'
        integer count=0
        esc=$'\E'
        ednum=
        tilde='~'
        esc2=$'\E\[\['
        edchar=
        eof=$'\004'
        # was map=( []= )
        map=( [_]=_ )
)
} 2> /dev/null

function comp_emacs {
        #printf "<%q-%q:%q:%q-" "${.sh.edchar}" "${.sh.edcol}" "${#.sh.edtext}" 
"${.sh.edtext}"
        if [[ ${.sh.edchar} == ${comp.tab} ]]; then
                if [[ -n ${comp.ednum} ]]; then
                        comp.count=1
                fi
                if (( ++comp.count == 1 )); then
                        .sh.edchar=${comp.comp}; return
                elif (( comp.count > 1 )); then
                        .sh.edchar=${comp.ednum}${comp.list}
                        comp.ednum=; return
                fi
                # notreached
        else
                comp.count=0
                # fallthrough
        fi
        if [[ ${.sh.edchar} == ${comp.esc}[0-9] ]]; then
                typeset ednum=${comp.ednum}
                comp.ednum=${.sh.edchar}
                .sh.edchar=${ednum}${comp.edchar}
                comp.edchar=; return
        elif [[ ${.sh.edchar} == [0-9] ]]; then
                # dtksh hack
                if [[ -n ${comp.edchar} ]]; then
                        comp.edchar=${comp.edchar}${.sh.edchar}
                        .sh.edchar=; return
                elif [[ -n ${comp.ednum} ]]; then
                        comp.ednum=${comp.ednum}${.sh.edchar}
                        .sh.edchar=; return
                fi
                # fallthrough
        elif [[ ${.sh.edchar} = [A-E] ]]; then
                # cygwin hack
                if [[ -n ${comp.edchar} ]]; then
                        .sh.edchar=${comp.edchar}${.sh.edchar}
                        # fallthrough
                fi
        fi
        # dtksh hack
        if [[ ${.sh.edchar} == ${comp.tilde} ]]; then
                if [[ -n ${comp.edchar} ]]; then
                        typeset edmap=${comp.map[${comp.edchar}${comp.tilde}]}
                        if [[ ${edmap} != ${comp.eof} ]] || \
                           (( .sh.edcol || ( ! .sh.edcol && ${#.sh.edtext} ) 
)); then
                                .sh.edchar=${comp.ednum}${edmap}
                                comp.ednum= comp.edchar=; return
                        elif [[ ${edmap} == ${comp.eof} ]] && (( ! .sh.edcol 
)); then
                                .sh.edchar=
                                comp.ednum= comp.edchar=; return
                        fi
                        # fallthrough
                fi
        # cygwin hack
        elif [[ ${.sh.edchar} == "${comp.esc2}" ]]; then
                comp.edchar=${.sh.edchar}
                .sh.edchar=; return
        elif [[ -n ${comp.map[${.sh.edchar}]} ]]; then
                typeset edmap=${comp.map[${.sh.edchar}]}
                if [[ ${edmap} != ${comp.eof} ]] || \
                   (( .sh.edcol || ( ! .sh.edcol && ${#.sh.edtext} ) )); then
                        .sh.edchar=${comp.ednum}${edmap}
                        comp.ednum=; return
                elif [[ ${edmap} == ${comp.eof} ]] && (( ! .sh.edcol )); then
                        .sh.edchar=
                        comp.ednum=; return
                fi
                # fallthrough
        # dtksh hack
        elif [[ -n ${comp.map[${.sh.edchar}${comp.tilde}]} ]]; then
                comp.edchar=${.sh.edchar}
                .sh.edchar=; return
        fi
        .sh.edchar=${comp.ednum}${.sh.edchar}
        comp.ednum=; return
}
trap comp_emacs KEYBD
function keybind {
        typeset c= act=a
        while getopts pu c; do act=${c}; done
        shift OPTIND-1
        case ${act} in
        a)
                while (( $# > 1 )); do
                        comp.map[$(print -- "$1")]=$(print -- "$2")
                        #comp.map[$1]=$2
                        shift 2
                done
                ;;
        p)
                for c in ${!comp.map[@]}; do
                        printf "%-8q => %q\n" "${c}" "${comp.map[${c}]}"
                done
                ;;
        u)
                if (( $# > 0 )); then
                        for c; do
                                unset ${comp.map[$(print -- "${c}")]}
                        done
                else
                        unset comp.map
                        comp.map=( [_]=_ )
                fi
                ;;
        esac
}
keybind $'\E[A' $'\020' $'\E[B' $'\016' $'\E[C' $'\006' $'\E[D' $'\002'
keybind $'\EOA' $'\020' $'\EOB' $'\016' $'\EOC' $'\006' $'\EOD' $'\002'
keybind $'\E[2~' ' ' $'\E[3~' $'\004' $'\E[1~' $'\001' $'\E[4~' $'\005'
keybind $'\E[L' ' ' $'\177' $'\004' $'\E[H' $'\001' $'\E[F' $'\005'
keybind $'\E[5~' $'\Eb' $'\E[6~' $'\Ef' $'\E[I' $'\Eb' $'\E[G' $'\Ef'
keybind $'\E[11~' $'\001man ' $'\E[[A' $'\001man ' $'\EOP' $'\001man '
#keybind -p
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to