UNIX / How to configure more specificly KSH93

Home | UNIX | Practical

How to configure more specificly KSH93

KSH common : pbraun.nethence.com/doc/shells/ksh.html
KSH93 : pbraun.nethence.com/doc/shells/ksh93.html
KSH88 : pbraun.nethence.com/doc/shells/ksh88.html
PDKSH : pbraun.nethence.com/doc/shells/pdksh.html
KSH programming : pbraun.nethence.com/doc/devel/ksh.html


Keybindings
The keybind function,
typeset -A Keytable
trap 'eval "${Keytable[${.sh.edchar}]}"' KEYBD
function keybind # key [action]
{
typeset key=$(print -f "%q" "$2")
case $# in
2) Keytable[$1]=' .sh.edchar=${.sh.edmode}'"$key"
;;
1) unset Keytable[$1]
;;
*) print -u2 "Usage: $0 key [action]"
return 2 # usage errors return 2 by default
;;
esac
}
Ref. www.kornshell.com/examples/keybind
To make either ^I or the TAB key work for both -- command and dir & filename completion -- use this keybind function,
keybind $'\t' $'\E\E'
To make ^L work, use this one,
keybind $'^L' 'echo -ne "\E[H\E[J"'$'\r'
Note ^L needs to be written into .kshrc using vi's ^V mode.
Note. if that doesn't work you may have some older terminal. Therefore either get your clear-screen code by doing,
infocmp | grep clear
or guess it based on this output against the ascii table,
cput clear | oc -d
man ascii
in example "0000000 033 [ H 033 [ J" gives "\E[H\E[J". Then try it out on the command line.
echo -ne "\E[H\E[J"
Once it works include it inside .kshrc + a carriage return ($'\'). See the keybinding example above.
Otherwise, there's always this brute force method with works everywhere,
keybind $'^L' $'clear\r'
Note ^L needs to be written into .kshrc using vi's ^V mode.


Configuration & profile
You can use the same for both: root and users,
cd ~/
ln -s ../.kshrc
ln -s ../.profile

For /.profile (/etc/profile is absent),
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin
ENV=~/.kshrc
LANG=C
umask 0022
Note. logname and hostname calls are using the PATH previously defined.
Note you may use LANG=en_US but on AIX keep LANG=C
Note for root you may prefer umask 0027,
[[ $USER == root ]] && umask 0027

For /.kshrc,
typeset -A Keytable
trap 'eval "${Keytable[${.sh.edchar}]}"' KEYBD
function keybind # key [action]
{
typeset key=$(print -f "%q" "$2")
case $# in
2) Keytable[$1]=' .sh.edchar=${.sh.edmode}'"$key"
;;
1) unset Keytable[$1]
;;
*) print -u2 "Usage: $0 key [action]"
return 2 # usage errors return 2 by default
;;
esac
}
set -o emacs
USER=${USER:-`logname`}
HOSTNAME=${HOSTNAME:-`hostname`}
[[ "$USER" == "root" ]] && PS1="${HOSTNAME%%.*}# " || PS1="${HOSTNAME%%.*}> "
[[ -x `which less 2>/dev/null` ]] && PAGER=less || PAGER=more
MAIL=/var/spool/mail/$LOGNAME
[[ -s $MAIL ]] && echo "You have mail."
MAILCHECK=10
keybind $'\t' $'\E\E'
keybind $'' 'echo -ne "\E[H\E[J"'$'\r'
alias mv='mv -i'
alias rm='rm -i'
alias ll='ls -alk'
Note. ^L needs to be written doing vi's ^V.

Unused bindings (works already),
keybind $'\EOA' $'\020' # Up key
keybind $'\EOB' $'\016' # Down key
keybind $'\EOC' $'\006' # Right key
keybind $'\EOD' $'\002' # Left key
keybind $'\EOH' $'\001' # Home key
keybind $'\EOP' $'\004' # Delete key
keybind $'\EOY' $'\005' # End key

Ununsed history feature (works already),
alias __A=$(print -n "\020")
alias __B=$(print -n "\016")
alias __C=$(print -n "\006")
alias __D=$(print -n "\002")

Other unused confs,
HOME=/home/$LOGNAME
if tty -s; then
    PAGER=less
    VISUAL=vi
    stty sane susp ^Z
    stty erase '^H'
    stty kill '^?'
    MAILPATH=path/1:path/2
fi
Note VISUAL is the same as EDITOR but overwrites it.


References
HP : docs.hp.com/en/B2355-90046/ch16s05.html
Korn : kornshell.com/doc/faq.html
www.cs.sun.ac.za/~akruger/red_hat_linux/rhl11.htm#E68E72
home.nyc.rr.com/computertaijutsu/ksh.html
www.unixguide.net/ibm/faq/faq1.401.shtml
www.idris.fr/su/divers/Exemple_fich_environ.html
marcg.developpez.com/ksh/
bp.noos.org/computer/ksh.html
wwwacs.gantep.edu.tr/docs/KornShell/faq.html
www.research.att.com/~gsf/download/gen/ast-ksh.html#ksh93%20changes
www.zenez.com/tmp/ou8faqz/cache/54.html
www.mail-archive.com/solaris_fr@x86.sun.com/msg00950.html
Keyboard trap : groups.google.fr/group/comp.unix.shell/browse_thread/thread/853905266fdd34ac/20541e5c0f9c59f2?hl=fr&lnk=st&q=%22David+Korn%22+ksh93+keybind#20541e5c0f9c59f2
Keyboard trap : www.unixinfo.org/books/ProUnixShellProg/ProUnixShellProg-Keybindi.html
Keyboard trap : groups.google.fr/group/alt.comp.editors.batch/browse_thread/thread/1fbcbc450d9dacb4/7819109fc978b1b1?hl=fr&lnk=st&q=ksh93+key+binding+question#7819109fc978b1b1




Sat Nov 8 12:19:48 CET 2008
       © 2008 Pierre-Philipp Braun