When doing filename autocompletion, append a trailing slash at the end of directory

names. We already do this when there is only one completion option but
in case of of multiple completion options, it wasn't being done.

ok christos@
This commit is contained in:
abhinav 2017-04-21 05:38:03 +00:00
parent 4c09db682e
commit 3a89c5769a
3 changed files with 30 additions and 22 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: filecomplete.c,v 1.44 2016/10/31 17:46:32 abhinav Exp $ */
/* $NetBSD: filecomplete.c,v 1.45 2017/04/21 05:38:03 abhinav Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
__RCSID("$NetBSD: filecomplete.c,v 1.44 2016/10/31 17:46:32 abhinav Exp $");
__RCSID("$NetBSD: filecomplete.c,v 1.45 2017/04/21 05:38:03 abhinav Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@ -354,10 +354,13 @@ _fn_qsort_string_compare(const void *i1, const void *i2)
* num, so the strings are matches[1] *through* matches[num-1].
*/
void
fn_display_match_list (EditLine *el, char **matches, size_t num, size_t width)
fn_display_match_list(EditLine * el, char **matches, size_t num, size_t width,
const char *(*app_func) (const char *))
{
size_t line, lines, col, cols, thisguy;
int screenwidth = el->el_terminal.t_size.h;
if (app_func == NULL)
app_func = append_char_function;
/* Ignore matches[0]. Avoid 1-based array logic below. */
matches++;
@ -385,8 +388,11 @@ fn_display_match_list (EditLine *el, char **matches, size_t num, size_t width)
thisguy = line + col * lines;
if (thisguy >= num)
break;
(void)fprintf(el->el_outfile, "%s%-*s",
col == 0 ? "" : " ", (int)width, matches[thisguy]);
(void)fprintf(el->el_outfile, "%s%s%s",
col == 0 ? "" : " ", matches[thisguy],
append_char_function(matches[thisguy]));
(void)fprintf(el->el_outfile, "%-*s",
(int) (width - strlen(matches[thisguy])), "");
}
(void)fprintf(el->el_outfile, "\n");
}
@ -533,7 +539,7 @@ fn_complete(EditLine *el,
* add 1 to matches_num for the call.
*/
fn_display_match_list(el, matches,
matches_num+1, maxlen);
matches_num+1, maxlen, app_func);
}
retval = CC_REDISPLAY;
} else if (matches[0][0]) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: filecomplete.h,v 1.10 2016/04/11 00:50:13 christos Exp $ */
/* $NetBSD: filecomplete.h,v 1.11 2017/04/21 05:38:03 abhinav Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -37,7 +37,8 @@ int fn_complete(EditLine *,
const wchar_t *, const wchar_t *, const char *(*)(const char *), size_t,
int *, int *, int *, int *);
void fn_display_match_list(EditLine *, char **, size_t, size_t);
void fn_display_match_list(EditLine *, char **, size_t, size_t,
const char *(*)(const char *));
char *fn_tilde_expand(const char *);
char *fn_filename_completion_function(const char *, int);

View File

@ -1,4 +1,4 @@
/* $NetBSD: readline.c,v 1.140 2017/01/09 03:09:05 christos Exp $ */
/* $NetBSD: readline.c,v 1.141 2017/04/21 05:38:03 abhinav Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
__RCSID("$NetBSD: readline.c,v 1.140 2017/01/09 03:09:05 christos Exp $");
__RCSID("$NetBSD: readline.c,v 1.141 2017/04/21 05:38:03 abhinav Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@ -1812,18 +1812,6 @@ _el_rl_tstp(EditLine *el __attribute__((__unused__)), int ch __attribute__((__un
return CC_NORM;
}
/*
* Display list of strings in columnar format on readline's output stream.
* 'matches' is list of strings, 'len' is number of strings in 'matches',
* 'max' is maximum length of string in 'matches'.
*/
void
rl_display_match_list(char **matches, int len, int max)
{
fn_display_match_list(e, matches, (size_t)len, (size_t)max);
}
static const char *
/*ARGSUSED*/
_rl_completion_append_character_function(const char *dummy
@ -1836,6 +1824,19 @@ _rl_completion_append_character_function(const char *dummy
}
/*
* Display list of strings in columnar format on readline's output stream.
* 'matches' is list of strings, 'len' is number of strings in 'matches',
* 'max' is maximum length of string in 'matches'.
*/
void
rl_display_match_list(char **matches, int len, int max)
{
fn_display_match_list(e, matches, (size_t)len, (size_t)max,
_rl_completion_append_character_function);
}
/*
* complete word at current point
*/