Home
|
UNIX
|
Practical
How to configure more specificly KSH93
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
}
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