Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Feb 1996 14:37:42 +0000 (GMT)
From:      Gabor Zahemszky <zgabor@CoDe.hu>
To:        deischen@iworks.InterWorks.org (Daniel M. Eischen)
Cc:        freebsd-questions@freebsd.org
Subject:   Re: cursor keys under Unix-shells
Message-ID:  <199602271437.OAA03436@CoDe.CoDe.hu>
In-Reply-To: <9602261729.AA25598@iworks.InterWorks.org> from "Daniel M. Eischen" at Feb 26, 96 11:29:53 am

next in thread | previous in thread | raw e-mail | index | archive | help
> How can I get to use the cursor keys under HP/UX ksh?

OK.  The trick is the next: at&t ksh uses specially named aliases to
make  some cursor keys working with command-line editing
f you use vi-mode, than whenever you type @x, ksh searches the alias
table for an alias named _x, and if if found, it switch @x, with the
value of the _x alias.  It's good for making macros, but nothing
else.  But there is a similar function  in the emacs (or gmacs)
mode.  If you type <ESC>x, ksh searches for an alias named _x, and
substitues  <ESC>x with the value of that alias.  The same is true
with  <ESC>[x nad alias __x.  OK.  On vt-52 (and like) terminals,
the cursor keys send the next sequence:
up: <ESC>A
down: <ESC>B
right: <ESC>C
left: <ESC>D
So, when somebody uses vt-52 like terminal, s/he has to make such
aliases:
alias _A=^P
alias _B=^N
alias _C=^F
alias _D=^B
n a vt100 (like) terminal, there is only one problem.  (As I know), 
cursor keys send different codes on numeric, and on application keypad 
mode.  <ESC>[A in one of them, and <ESC>OA in the other.  But it's not
avery big problem.  You have to make two group of aliases, one
for numeric, and one for appl. mode:
alias __A=^P
alias __B=^N
alias __C=^F
alias __D=^B
and
alias _OA=^P
alias _OB=^N
alias _OC=^F
alias _OD=^B
And, of course set -o emacs.  Two things:
a) in all of the aliases, when I typed ^X, you have to make the REAL
control-X character, not that literal ^ and X
b) in the _OX aliases, they are big o-s, not zeros.

One of the alias-group works most of the modern (vt-something) like 
terminals, so it would be the best to put all of them in the
Korn-shell's ENV-file, eg:
case "$-" in
	*i*)	# interactive shell
	# a little hack for command-line editing
	# vt-52 like terminals
	alias _A=^P
	...
	# vt-100 in numeric mode
	alias __A=^P
	...
	# vt-100 in appl. mode
	alias _OA=^P
	...
	# and the main thing:
	set -o emacs
	;;
	*)	# non-interactive mode of the shell
	#I don't know, what would be good to be here
	;;
esac

As I know, the binding are good for xterms, Wyses, etc.
You can make this in pdksh, too, but not with aliases, but with
the bind command of pdksh (it defines the normal vt-100 bindings
so you need it only on appl. mode, or vt52-like terminals):
#vt52:
bind '^[A=up-history'
bind '^[B=down-history'
bind '^[C=forward-char'
bind '^[D=backward-char'
# vt100: in normal mode:
bind '^[[=prefix-2'
# vt100: in appl. mode
bind '^[O=prefix-2'
# and the cursor keys in both mode
bind '^XA=up-history'
bind '^XB=down-history'
bind '^XC=forward-char'
bind '^XD=backward-char'
# and the main:
set -o emacs
But you have to type ^[ and ^X LITERALLY! (a ^ and a [ or X)
I have another ``case'' in my .kshrc, because in our local
net, there are machines, some of them uses ksh.att, some of them pdksh:
case "$KSH_VERSION" in
	*[pP][dD]*)	# pdksh
	# the pdksh bindings
	*)	# the real att 
	# the aliases of it.
esac

If you have some other shells - like bash, ash, zsh, etc - which use this ENV
file it's another problem.

OK, pdksh ends.

If you  use at&t ksh, with an HP-terminal, there is another
problem: the HP terminals use the cursor keys internally, so
you have to switch it off.  I have to look for it in the terminal
manuals, but there is something named ~ send function key codes, 
or like.  You have to switch it off manually.  It has a terminfo
variable, so you have to only type something like this:
tput smkx (I don't know the correct name, sorry, look in in the manual)
And another ``feature'' vi, and some others, switch it on.!
Bye, Gabor

-- 
	Gabor Zahemszky <zgabor@CoDe.hu>

-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-
Earth is the cradle of human sense, but you can't stay in the cradle forever.
						Tsiolkovsky



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199602271437.OAA03436>