Subject: Re: CVS commit: basesrc/bin/ksh
To: Joerg Klemenz <joerg@gmx.net>
From: Greg A. Woods <woods@weird.com>
List: tech-userlevel
Date: 09/27/2002 15:32:16
[ On Friday, September 27, 2002 at 18:07:06 (+0000), Joerg Klemenz wrote: ]
> Subject: Re: CVS commit: basesrc/bin/ksh
>
> Just one thing: Our ksh has some highly annoying bugs and/or
> non-features in interactive use mostly:
> 
> home/end/ctrl-arrow won't work, also Fn or ^L etc.
> Just try (in emacs mode) bind "^[[8~"=end-of-line
> (bind -m ..=^E won't work too)

RTFM:

                Note
              that although only two prefix  characters  (usually
              ESC  and  ^X)  are  supported, some multi-character
              sequences can be supported.   The  following  binds
              the arrow keys on an ANSI terminal, or xterm (these
              are in  the  default  bindings).   Of  course  some
              escape sequences won't work out quite this nicely:

              bind '^[['=prefix-2
              bind '^XA'=up-history
              bind '^XB'=down-history
              bind '^XC'=forward-char
              bind '^XD'=backward-char

Since <HOME> is in ANSI x3.64 by default <ESC>[H, and <END> is by
default <ESC>[F, extending the above suggests:

	bind '^XH'=beginning-of-line
	bind '^XF'=end-of-line

And, indeed those to commands alone work just fine (since if I'm not
mistaken '^[['=prefix-2 is already a default binding).
 

> Also the scrolling (non-wrapping) line editor sucks big time.

It works just fine -- it just works differently than some other
interactive line editors you might be more familiar with.


> Also the lack of a .kshrc file or whatever forces you to put ksh
> specific stuff in .profile or $ENV and ifdef it out which doesnt
> always work.

Huh?  $ENV is standard POSIX shell behaviour and has been a standard
feature of AT&T ksh for nearly forever (1983?).  You don't get a
~/.kshrc file to work by default with AT&T KSH, you have to use $ENV.

And $ENV does always work reliably if you use it properly:

fragment from ~/.profile that I've used for the past ten years:

	if [ ${RANDOM:-0} -ne ${RANDOM:-0} -a -z "${BASH}" ] ; then
		# we're running ksh
		if [ -r $HOME/.kshlogin ] ; then
			. $HOME/.kshlogin
		fi
	fi

similarly aged fragment from my ~/.kshlogin:

	export ENVFILE=$HOME/.kshrc

	if [ -n "$ENVFILE" -a -r "$ENVFILE" ] ; then
		# the one in the book says....
		#
		#export ENV='${ENVFILE[(_$-=0)+(_=1)-_${-%%*i*}]}'
		#
		# this one seems more correct, and I think was what Korn posted
		# to Usenet once upon a time (it also works with all the
		# versions of ksh I've run across, including ksh-85 and AIX-3.2)
		#
		export ENV='${ENVFILE[(_$-=1)+(_=0)-(_$-!=_${-%%*i*})]}'
	fi


see the whole mess in the files in this archive:

	ftp://ftp.weird.com/pub/local/dotfiles.tar.gz

> Is PD KSH still maintained? The copyright suggests its from '99?

for more info see:

	http://www.cs.mun.ca/~michael/pdksh/

-- 
								Greg A. Woods

+1 416 218-0098;            <g.a.woods@ieee.org>;           <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>