vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit cdb3a32be2389ef3ef2edca21af68ef0a9414e7b
parent 406dd47c049015a20e6a060a1e8af2bce3d17cd1
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 19 May 2016 15:45:22 +0200

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.

Diffstat:
Mmain.c | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git 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 }); }