lineedit: on tab completion, show filenames obly in all cases (bash compat)
function old new delta complete_cmd_dir_file 731 730 -1 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
parent
76939e7b72
commit
3926363214
@ -751,6 +751,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
|
|||||||
continue; /* don't print an error */
|
continue; /* don't print an error */
|
||||||
|
|
||||||
while ((next = readdir(dir)) != NULL) {
|
while ((next = readdir(dir)) != NULL) {
|
||||||
|
unsigned len;
|
||||||
const char *name_found = next->d_name;
|
const char *name_found = next->d_name;
|
||||||
|
|
||||||
/* .../<tab>: bash 3.2.0 shows dotfiles, but not . and .. */
|
/* .../<tab>: bash 3.2.0 shows dotfiles, but not . and .. */
|
||||||
@ -767,18 +768,15 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
|
|||||||
if (stat(found, &st) && lstat(found, &st))
|
if (stat(found, &st) && lstat(found, &st))
|
||||||
goto cont; /* hmm, remove in progress? */
|
goto cont; /* hmm, remove in progress? */
|
||||||
|
|
||||||
/* save only name if we scan PATH */
|
/* Save only name */
|
||||||
if (paths[i] != dirbuf)
|
len = strlen(name_found);
|
||||||
strcpy(found, name_found);
|
found = xrealloc(found, len + 2); /* +2: for slash and NUL */
|
||||||
|
strcpy(found, name_found);
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
unsigned len1 = strlen(found);
|
/* name is a directory, add slash */
|
||||||
/* name is a directory */
|
found[len] = '/';
|
||||||
if (found[len1-1] != '/') {
|
found[len + 1] = '\0';
|
||||||
found = xrealloc(found, len1 + 2);
|
|
||||||
found[len1] = '/';
|
|
||||||
found[len1 + 1] = '\0';
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* skip files if looking for dirs only (example: cd) */
|
/* skip files if looking for dirs only (example: cd) */
|
||||||
if (type == FIND_DIR_ONLY)
|
if (type == FIND_DIR_ONLY)
|
||||||
@ -796,10 +794,8 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
|
|||||||
if (paths != path1) {
|
if (paths != path1) {
|
||||||
free(paths[0]); /* allocated memory is only in first member */
|
free(paths[0]); /* allocated memory is only in first member */
|
||||||
free(paths);
|
free(paths);
|
||||||
} else if (dirbuf) {
|
|
||||||
pf_len += strlen(dirbuf);
|
|
||||||
free(dirbuf);
|
|
||||||
}
|
}
|
||||||
|
free(dirbuf);
|
||||||
|
|
||||||
return pf_len;
|
return pf_len;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user