Page MenuHomeFreeBSD

D29361.id86110.diff
No OneTemporary

D29361.id86110.diff

Index: bin/sh/histedit.c
===================================================================
--- bin/sh/histedit.c
+++ bin/sh/histedit.c
@@ -39,6 +39,8 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
+#include <sys/stat.h>
+#include <dirent.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
@@ -72,6 +74,7 @@
static char *fc_replace(const char *, char *, char *);
static int not_fcnumber(const char *);
static int str_to_event(const char *, int);
+static unsigned char sh_complete(EditLine *, int);
/*
* Set history and editing status. Called whenever the status may
@@ -122,7 +125,7 @@
el_set(el, EL_PROMPT, getprompt);
el_set(el, EL_ADDFN, "sh-complete",
"Filename completion",
- _el_fn_complete);
+ sh_complete);
} else {
bad:
out2fmt_flush("sh: can't initialize editing\n");
@@ -519,3 +522,71 @@
return (0);
}
#endif
+
+static char **sh_matches(const char *text, int start, int end)
+{
+ char *dirname, *path, *free_path;
+ char execpath[PATH_MAX];
+ char **matches;
+ size_t i, size;
+
+ if (start > 0)
+ return NULL;
+ i = 0;
+ size = 16;
+ matches = NULL;
+ free_path = NULL;
+ if ((free_path = path = strdup(pathval())) == NULL)
+ goto out;
+ if ((matches = malloc(size * sizeof (char *))) == NULL)
+ goto out;
+ while ((dirname = strsep(&path, ":")) != NULL) {
+ DIR *dir;
+ struct dirent *entry;
+
+ if ((dir = opendir(dirname)) == NULL)
+ continue;
+ while ((entry = readdir(dir)) != NULL) {
+ struct stat statb;
+ int sn;
+
+ if (strncmp(entry->d_name, text, end - start) != 0)
+ continue;
+ sn = snprintf(execpath, sizeof execpath, "%s/%s", dirname,
+ entry->d_name);
+ if (sn < 0 || sn >= (int)(sizeof execpath))
+ continue;
+ if (stat(execpath, &statb) == -1 || !S_ISREG(statb.st_mode))
+ continue;
+ if (++i >= size) {
+ char **rloc_matches;
+
+ size *= 2;
+ rloc_matches = realloc(matches, size * sizeof (char *));
+ if (rloc_matches == NULL)
+ goto out;
+ matches = rloc_matches;
+ }
+ matches[i] = strdup(entry->d_name);
+ }
+ closedir(dir);
+ }
+out:
+ free(free_path);
+ if (i == 0) {
+ free(matches);
+ return NULL;
+ }
+ matches[0] = strdup(i == 1 ? matches[1] : text);
+ matches[++i] = NULL;
+
+ return matches;
+}
+
+unsigned char
+sh_complete(EditLine *sel, int ch __unused)
+{
+ return (unsigned char)fn_complete(sel, NULL, sh_matches,
+ L" \t\n\"\\'`@$><=;|&{(", NULL, NULL, (size_t)100,
+ NULL, &((int) {0}), NULL, NULL);
+}
Index: bin/sh/myhistedit.h
===================================================================
--- bin/sh/myhistedit.h
+++ bin/sh/myhistedit.h
@@ -38,6 +38,8 @@
extern EditLine *el;
extern int displayhist;
+#include <filecomplete.h>
+
void histedit(void);
void sethistsize(const char *);
void setterm(const char *);
Index: lib/libedit/Makefile
===================================================================
--- lib/libedit/Makefile
+++ lib/libedit/Makefile
@@ -65,7 +65,7 @@
editline.3 tok_wreset.3 \
editline.3 tok_wstr.3
-INCS= histedit.h
+INCS= histedit.h filecomplete.h
SRCS+= common.h emacs.h fcns.h func.h help.h vi.h
CLEANFILES+= common.h emacs.h fcns.h func.h help.h vi.h

File Metadata

Mime Type
text/plain
Expires
Wed, Sep 30, 5:50 AM (3 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39927483
Default Alt Text
D29361.id86110.diff (3 KB)

Event Timeline