Skip to content

Commit

Permalink
vis: tweak completion commands
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martanne committed May 19, 2016
1 parent 09f9cf9 commit 42e653f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand All @@ -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 });
}
Expand Down

0 comments on commit 42e653f

Please sign in to comment.