Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ksh: Filename completion: How to set [tab]

35 views
Skip to first unread message

Bill Lund

unread,
Feb 28, 1997, 3:00:00 AM2/28/97
to

Hello,

Currently I can hit [esc][esc] to get filename completion, but this is
unsatisfactory. How can I set up [tab] to be the completion key?

Thanks,
Bill.

Brian S Hiles

unread,
Mar 3, 1997, 3:00:00 AM3/3/97
to

Bill Lund (b...@unx.dec.com) wrote:
: Hello,

: Currently I can hit [esc][esc] to get filename completion, but this is
: unsatisfactory. How can I set up [tab] to be the completion key?

Short: why isn't ESC-ESC sufficient?
Shorter: upgrade to ksh93.
Shortest: you can't.

-Brian
--
,---. ,---. ,---. ,---. ,---. ,---. ,---.
/ _ \ / _ \ / _ \ / _ \ / _ \ / _ \ / _ \
.' / \ `.' / mailto:bsh2...@challenger.atc.fhda.edu \ `.' / \ `.
__,' `.___,' `.___,' `.___,' `.___,' `.___,' `.___,' `.__

Jeffrey Korn

unread,
Mar 4, 1997, 3:00:00 AM3/4/97
to

In article <slrn5hjobg...@joshua.insight.att.com>,
Vikas Agnihotri <vi...@insight.att.com> wrote:

>On Fri, 28 Feb 1997 17:01:40 -0500, Bill Lund <b...@unx.dec.com> wrote:
>>Hello,
>
>>Currently I can hit [esc][esc] to get filename completion, but this is
>>unsatisfactory. How can I set up [tab] to be the completion key?
>
>You cannot. Upgrade to 'zsh' For more details,
>http://www.math.fu-berlin.de/~guckes/zsh

You can, without downgrading to zsh! Make sure you're using ksh93
(from www.research.att.com/sw/tools/reuse) which has the ability to
do arbitrary key bindings. Then try this:

trap 'eval "${Keytable[${.sh.edchar}]}"' KEYBD

function keybind # key action
{
typeset key=$(print -rf "%q" "$2")
case $# in
2) Keytable[$1]=' .sh.edchar=${.sh.edmode}'"$key"
;;
1) unset Keytable[$1]
;;
*) print -u2 "Usage: $0 key [action]"
;;
esac
}


keybind $'\t' $'\E\E'

--

Jeff Korn
j...@cs.princeton.edu

ptd-on...@tiny1.demon.co.uk

unread,
Mar 5, 1997, 3:00:00 AM3/5/97
to

According to Vikas Agnihotri <vi...@insight.att.com>:

>On Fri, 28 Feb 1997 17:01:40 -0500, Bill Lund <b...@unx.dec.com> wrote:
>>Hello,
>
>>Currently I can hit [esc][esc] to get filename completion, but this is
>>unsatisfactory. How can I set up [tab] to be the completion key?
>
>You cannot. Upgrade to 'zsh' For more details,
>http://www.math.fu-berlin.de/~guckes/zsh

Well, actually it depends of what variant of ksh you're using.
pdksh has an option to 'set -o' called vi-tabcomplete which sets this
behaviour if you're using vi-mode for command editing. I believe
it's the default in emacs-mode.

ptd-on...@tiny1.demon.co.uk

unread,
Mar 5, 1997, 3:00:00 AM3/5/97
to

Gerd Marquardt

unread,
Mar 5, 1997, 3:00:00 AM3/5/97
to

In article <slrn5hqokl...@joshua.insight.att.com>, vi...@insight.att.com (Vikas Agnihotri) writes:
|> On 3 Mar 1997 22:13:50 GMT, Brian S Hiles <bsh2...@news.fhda.edu> wrote:

|> >Bill Lund (b...@unx.dec.com) wrote:
|> >: Hello,
|> >: Currently I can hit [esc][esc] to get filename completion, but this is
|> >: unsatisfactory. How can I set up [tab] to be the completion key?
|>
|> >Shorter: upgrade to ksh93.
|>
|> Where can I get a copy of ksh 93? How do I know what Version of ksh I
|> currently have? What are the new bells and whistles in ksh 93? Thanks for any
|> information you can provide.
|>
|> --Vikas

Loo at:

http://www.research.att.com/sw/tools/reuse/

Gerd Marquardt
RRZN / Universitaet Hannover marq...@rrzn.uni-hannover.de
Schlosswender Str. 5 Tel. +49-511-762-4727
D-30159 Hannover fax: +49-511-762-3003

Brian S Hiles

unread,
Mar 5, 1997, 3:00:00 AM3/5/97
to

Vikas Agnihotri (vi...@insight.att.com) wrote:

: On 3 Mar 1997 22:13:50 GMT, Brian S Hiles <bsh2...@news.fhda.edu> wrote:
: : : Bill Lund (b...@unx.dec.com) wrote:
: : : Hello,
: : : Currently I can hit [esc][esc] to get filename completion, but this is
: : : unsatisfactory. How can I set up [tab] to be the completion key?
: : Shorter: upgrade to ksh93.
: Where can I get a copy of ksh 93? How do I know what Version of ksh I
: currently have? What are the new bells and whistles in ksh 93? Thanks for any
: information you can provide.

(1)
The easiest place is the new URL that will provide links to the AT&T
download site:

http://www.kornshell.com # it has example ksh93 code!

I see that you work at AT&T! Be sure then to thank Mr. David Korn himself
for his kind and worthy decision to make ksh93 available for public use!

(2)
It's a general solution and somewhat more than you presumable asked for,
but reading the source will answer the above question better than I ever
could here:

# whichshell 2>&- || shtype=SH_OLD : do _not_ eliminate this comment line!
#*TAG:53722 8:Mar 3 1997:0755:sh.d/whichshell:whichshell:
# @(#)whichshell.sh 1.0 1996/05 bsh2...@atc.fhda.edu (Brian S. Hiles)
# Inspired by a script by: hei...@hsysnbg.nbg.sub.org (Heiner Steven)
#
# Suppose one desires a script be run regardless of knowledge of shell type,
# or that different versions of such script be run depending on the features
# of that shell version (instead of programming for the lowest common denom-
# inator), or simply wish to know the shell name and version currently running.
# This can serve as a "meta-shell" on top of just such a situation, instead
# of providing multiple scripts or relying on the value of the variable SHELL.
#
# usage:
# whichshell [script [parameter(s)]]
#
# With no arguments, the determined value of <shell> is printed
# to stdout. If this cannot be determined, $SHELL is assumed if
# set and non-null, otherwise string "UNKNOWN". With <script>
# argument and optional <parameter(s)>, the script <script>.<shell>
# is sourced with its positional parameters set to <parameter(s)>.
#
# example:
# csh -f whichshell ./script p1 p2 p3
# ksh whichshell ./script p1 p2 p3
# sh whichshell ./script p1 p2 p3
#
# It is assumed that files "./script.{CSH,KSH_88,SH}" exist
# having valid csh, ksh[88], and sh code, respectively. One
# may create links "script.SH" and "script.KSH_88" that point to
# "script.KSH_93", and a link "script.CSH" to a "script.TCSH".
#
# return value:
# For the case of no arguments:
# 0 if the shell is able to be determined, else 1.
# else,
# if the sourced file does not exist: 1, else the same
# as above, unless there is an explicit "exit" therein.
#
# knows bash 1.x/2.x, csh, ksh 86/88/93, old sh, posix sh, sh, tcsh, and zsh.
# this script cannot be sourced; it must be executed within a subshell.
# positional parameters cannot have embedded whitespace or special characters.
# comments indicate the latest shell version tested, on the OS indicated.
# bash 1.x may attempt to source $ENV script meant for ksh or other shells.
# to be truly robust for very old sh's: eliminate all comments but the first.
# TO DO: pdksh; differentiate between zsh 2.x and zsh 3.x ?

#1 LEAST COMMON DENOMINATOR
unset a || shtype=SH_OLD # ignore potential error message
set a = "$*"
test "$a" = "$*" && goto CSH

#2 BOURNE FAMILY
case $3 in
'') shcmd='echo ' ;;
*) set -- $3
shcmd=". ${1:?}."
shift ;;
esac
LINENO= RANDOM= a=$[1] retval=0
a=2 a=$[3] wait 2>&-
case $a$LINENO:$RANDOM in
1*) if (: ${!a}) 2>&-
then shtype=BASH_2X # bash 2.00 (IRIX 5.x)
else shtype=BASH_1X # bash 1.14.7(2) (IRIX 5.x)
fi ;;
$\[3]:[0-9]*)
shtype=KSH_86 ;; # ksh 6/3/86
$\[3][0-9]*)
shtype=KSH_88 ;; # ksh 11/16/88f-beta4 (IRIX 5.x)
$\[1][0-9]*)
# some ksh88s are modified to apparently conform to POSIX 1003.2
if (: ${.sh.version}) 2>&-
then shtype=KSH_93 # ksh M-12/28/93e (IRIX 5.x)
else shtype=KSH_88 # ksh 11/16/88f (AIX 4.x, OSF/1 3.x)
#shtype=KSH_88POSIX # ksh 11/16/88f (AIX 4.x, OSF/1 3.x)
fi ;;
$\[3]:) shtype=SH_POSIX ;; # sh SVR4 (Unixware)
2:) case $shtype in
SH_OLD) ;; # sh (V7, BSD4.x, Ultrix)
*) if (_(){ :;}) 2>&-
then shtype=SH # sh SVR2/3
else shtype=SH_OLD
fi ;;
esac ;;
3*) shtype=ZSH ;; # zsh 2.3.1 (IRIX 5.x)
*) retval=1 shtype=`
IFS=/
set -- ${SHELL:-UNKNOWN}
until test \$# = 1
do shift
done
echo "\$1"
` ;;
esac
eval $shcmd$shtype
exit $retval

#3 CSHELL FAMILY
CSH:
if ("X$a" == X) then
set shcmd = 'echo '
else
set argv = ($a) shcmd = "source $1."
endif
set a = /b/c.d.e retval = 0
switch ($a:t:r:e)
case c:d:e:r:e: # csh (SunOS 4.x)
case c.d.e:r:e: # csh (IRIX 5.x)
set shtype = CSH
breaksw
case d:
set shtype = TCSH # tcsh 6.04 (IRIX 5.x)
breaksw
default:
if ! ($?shell) set shell = UNKNOWN retval = 1
if ("X$shell" == X) set shell = UNKNOWN retval = 1
set shtype = $shell:t
breaksw
endsw
eval $shcmd$shtype
exit $retval
--

# example:
$ whichshell
KSH_93

(3)
Subject: Re: ksh93 features
Newsgroups: comp.unix.shell

Now that ksh93 is available for free, more systems should be including
it as a distribution shell, and ksh93 has quite unique features
specifically revolving around an expanded notion of _variable_
definition, reference, and type attribute. New and fascinating scripts
will be written in the future using these features as more and more
people experiment with them!

+ classes:
ksh93 (will have) object oriented extensions, on a variable
by variable nature.

+ associative arrays:
typeset -A critique
critique[book1]='it stinks!'

+ "self knowledge" of its own variable namespace:
print ${!_q*} will print all variables names beginning with "_q".
print ${!_q[*]} will print all indices of array _q.

+ compound variables and floating point attributes:
point=(
typeset -F x=0.1
typeset -F y=0.2
typeset -F z=0.3
)
$ print ${point.x}
0.1

+ "discipline functions" to create "smart" variables that know when they are
set, unset, or referenced:
function date.get
{ .sh.value=$(date)
}
$ print $date
Fri Dec 6 11:30:25 PST 1996
$ print $date
Fri Dec 6 11:30:29 PST 1996

+ the KEYBD trap:
# facility for binding an arbitrary character
# to a function or command sequence.
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
}

+ lots and LOTS of cool new features not mentioned here!

J.J. Keijser

unread,
Mar 7, 1997, 3:00:00 AM3/7/97
to

In article <331755...@unx.dec.com>, Bill Lund <b...@unx.dec.com> wrote:
>Hello,
>
>Currently I can hit [esc][esc] to get filename completion, but this is
>unsatisfactory. How can I set up [tab] to be the completion key?
>
With ksh88 you can't. With ksh93 you can but it's quite elaborate. You can
determine your ksh version by
1. set -o emacs
2. press ctrl-v

The release date should come up

HTH,

JJ


----------------------------------------------------------
*NOTE*
My Email return address is not correct
in order to avoid mass mailings...
These are the correct addresses:

Jan Just (JJ) Keijser
SMTP: j.j.k...@siep.shell.com
X400: C=NL A=400NET P=SHELL O=SIEP RIJSWIJK
OU1=EPT-RO OU2=OPENMAIL S=KEIJSER I=JJ
or
SMTP: Keij...@logica.com
X400: C=GB A=ATTMAIL P=Logica O=LBV OU1=LBVRTDA S=KEIJSERJJ

(who said X400 addresses aren't easy to remember :-)

Where do you want to crash today?
My views are my own...
flames > /dev/null 2>&1
----------------------------------------------------------

0 new messages