From c3bbd835fca0ba184f191b270d9aebfc2466be82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sun, 25 Sep 2016 10:57:01 +0200 Subject: vis: move file name and word completion logic to a shell script The shell script should be reviewed for quoting issues, currently it allows command injections as in: $ vis-complete "'; rm -f some-file; echo " However it is intended for interactive usage and from within vis it is only ever called with a valid completion prefix. The file name completion logic now supports nested directories. Close #347 --- main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 485478e..b0b932d 100644 --- a/main.c +++ b/main.c @@ -2131,8 +2131,7 @@ static const char *complete_word(Vis *vis, const char *keys, const Arg *arg) { Buffer cmd; buffer_init(&cmd); char *prefix = get_completion_prefix(vis); - if (prefix && buffer_printf(&cmd, "tr -cs '[:alnum:]_' '\n' | grep '^%s.' | sort -u | " - VIS_MENU " -b | sed 's/^%s//' | tr -d '\n'", prefix, prefix)) { + if (prefix && buffer_printf(&cmd, VIS_COMPLETE " --word '%s'", prefix)) { Filerange all = text_range_new(0, text_size(txt)); insert_dialog_selection(vis, &all, (const char*[]){ buffer_content0(&cmd), NULL }); } @@ -2145,8 +2144,7 @@ static const char *complete_filename(Vis *vis, const char *keys, const Arg *arg) Buffer cmd; buffer_init(&cmd); char *prefix = get_completion_prefix(vis); - if (prefix && buffer_printf(&cmd, "ls -1 | grep '^%s.' | sort | " - VIS_MENU " -b | sed 's/^%s//' | tr -d '\n'", prefix, prefix)) { + if (prefix && buffer_printf(&cmd, VIS_COMPLETE " --file '%s'", prefix)) { Filerange empty = text_range_new(0, 0); insert_dialog_selection(vis, &empty, (const char*[]){ buffer_content0(&cmd), NULL }); } -- cgit v1.2.3