From 42e653f9913d32f49981c85f41d009f42b89d523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 19 May 2016 15:45:22 +0200 Subject: vis: tweak completion commands Change tr command to split words, this won't properly work with Unicode but should at least avoid unwanted non-word symbols and be POSIX conformant. A possible alternative would be to use grep -o -E '\w+' while the -o option is not part of POSIX it seems to be mostly supported. However the \w regex syntax might not be supported. Force ls(1) output to be linewise and surpress the same prefix. Change sed invocation to only replace proper prefixes. --- main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 4b5d2ea..0097e3f 100644 --- a/main.c +++ b/main.c @@ -2147,8 +2147,8 @@ 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 \" ;:$<>#?{}()[],.'\" '\n' | " - " grep '^%s.' | sort | uniq | " VIS_MENU " | sed 's/%s//' | tr -d '\n'", prefix, prefix)) { + if (prefix && buffer_printf(&cmd, "tr -cs '[:alnum:]_' '\n' | grep '^%s.' | sort -u | " VIS_MENU + " | sed 's/^%s//' | tr -d '\n'", prefix, prefix)) { Filerange all = text_range_new(0, text_size(txt)); insert_dialog_selection(vis, &all, (const char*[]){ buffer_content0(&cmd), NULL }); } @@ -2161,8 +2161,8 @@ 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 | grep '^%s' | sort | " VIS_MENU - " | sed 's/%s//' | tr -d '\n'", prefix, prefix)) { + if (prefix && buffer_printf(&cmd, "ls -1 | grep '^%s.' | sort | " VIS_MENU + " | sed 's/^%s//' | tr -d '\n'", prefix, prefix)) { Filerange empty = text_range_new(0, 0); insert_dialog_selection(vis, &empty, (const char*[]){ buffer_content0(&cmd), NULL }); } -- cgit v1.2.3