Project

General

Profile

Actions

Bug #1281

closed

[PATCH] Add `set -o tabcomplete' to /bin/sh.

Added by y0netan1 about 15 years ago. Updated almost 15 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

Description

When set, it binds <tab> to the libedit filename completion function.
Taken-From: NetBSD
---
bin/sh/histedit.c | 6 ++++
bin/sh/options.h | 4 ++-
bin/sh/sh.1 | 10 +
++++++++
3 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c
index 797685a..b0a8a6b 100644
--- a/bin/sh/histedit.c
+++ b/bin/sh/histedit.c
@ -67,6 +67,7 @ History hist; / history cookie /
EditLine *el; /
editline cookie */
int displayhist;
static FILE *el_in, *el_out, *el_err;
+unsigned char _el_fn_complete(EditLine *, int);

STATIC char *fc_replace(const char *, char *, char *);

@ -124,6 +125,9 @ histedit(void)
if (hist)
el_set(el, EL_HIST, history, hist);
el_set(el, EL_PROMPT, getprompt);
+ el_set(el, EL_ADDFN, "rl-complete",
+ "ReadLine compatible completion function",
+ _el_fn_complete);
} else {
bad:
out2str("sh: can't initialize editing\n");
@ -140,6 +144,8 @ bad:
el_set(el, EL_EDITOR, "vi");
else if (Eflag)
el_set(el, EL_EDITOR, "emacs");
+ el_set(el, EL_BIND, "^I",
+ tabcomplete ? "rl-complete" : "ed-insert", NULL);
el_source(el, NULL);
}
} else {
diff --git a/bin/sh/options.h b/bin/sh/options.h
index 3ca1c99..c8ee216 100644
--- a/bin/sh/options.h
++ b/bin/sh/options.h
@ -67,8 +67,9 @ struct shparam {
#define privileged optlist15.val
#define Tflag optlist16.val
#define Pflag optlist17.val
#define tabcomplete optlist18.val

-#define NOPTS 18
+#define NOPTS 19

struct optent {
const char *name;
@ -96,6 +97,7 @ struct optent optlist[NOPTS] = { { "privileged", 'p', 0 }, { "trapsasync", 'T', 0 }, { "physical", 'P', 0 },
+ { "tabcomplete", '\0', 0 },
};
#else
extern struct optent optlist[NOPTS];
diff --git a/bin/sh/sh.1 b/bin/sh/sh.1
index 19ca003..062c26e 100644
--- a/bin/sh/sh.1
++ b/bin/sh/sh.1
@ -315,6 +315,12 @ Write each command
variable)
to standard error before it is executed.
Useful for debugging.
.It "\ \ " Em tabcomplete
Enables filename completion in the command line editor.
+Typing a tab character will extend the current input word to match a
+filename.
+If more than one filename matches it is only extended to be the common prefix.
+Typing a second tab character will list all the matching names.
.El
.Pp
The
@ -2279,3 +2285,7 @ was originally written by
The
.Nm
utility does not recognize multibyte characters.
.Pp
+The characters generated by filename completion should probably be quoted
+to ensure that the filename is still valid after the input line has been
+processed.
--
1.6.0.6

--k1lZvvs/B4yU6o8G--


Files

sh-tabcomplete.diff (3.43 KB) sh-tabcomplete.diff qhwt+dfly, 03/29/2009 06:09 AM
Actions #1

Updated by dillon about 15 years ago

:YONETANI Tomokazu wrote:
:> Hello.
:> I played with NetBSD the other day, and found that their version of
:> bourne shell has a nice file name completion feature, which we don't
:> have. The attached patch adds `tabcomplete' option, which turns on
:> this file name completion feature, which defaults to off.
:
:Is there any reason to default to off?
:
:Also, why is -o emacs off by default?
:
:cheers
: simon
:

We should probably follow whatever NetBSD does there, but there is
no reason we can't turn it on in the default /etc/profile.
-Matt
Matthew Dillon
&lt;&gt;
Actions #2

Updated by joerg about 15 years ago

NetBSD enables it in /root/.profile. Putting it in /etc/profile is bad
for two reasons:
(a) That file is processed by many !/bin/sh shells as well.
(b) Users can't overwrite that file directly.

Joerg

Actions #3

Updated by corecode about 15 years ago

I don't see any harm in enabling it by default.

cheers
simon

Actions #4

Updated by joerg about 15 years ago

[For those searching for it, via .shrc -> /etc/shrc]

Joerg

Actions #5

Updated by qhwt+dfly almost 15 years ago

Please find attached a new version, which turns it on by default
only for interactive shell.

Actions #6

Updated by qhwt+dfly almost 15 years ago

[sh-tabcomplete.diff]
If no objection is raised, I'm planning to commit this version
by this weekend.

Cheers.

Actions #7

Updated by corecode almost 15 years ago

committed in 3f2d021a05994ae79be0e85e1895723e818c37e9

Actions

Also available in: Atom PDF