DragonFly submit List (threaded) for 2009-02
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]
[PATCH] Add `set -o tabcomplete' to /bin/sh.
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 optlist[15].val
#define Tflag optlist[16].val
#define Pflag optlist[17].val
+#define tabcomplete optlist[18].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--
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]