vis

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

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

commit f0368b130a05e8758a36912c0d652a2a6ae49a43
parent 6587abbdda58cc7c36a118b986a5f06f09d432ae
Author: Tim Allen <screwtape@froup.com>
Date:   Sat,  8 Oct 2016 16:05:21 +1100

Quote meta-characters in the completion pattern.

Because we're completing text from the document, we can't assume it's
going to be a sensible regex pattern, or glob pattern, let alone both,
so we should quote the pattern before we hand it off to helper tools
like grep and find.

Diffstat:
Mvis-complete | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/vis-complete b/vis-complete @@ -1,6 +1,9 @@ #!/bin/sh set -e +basic_regex_quote() { printf "%s" "$1" | sed 's|[\\.*^$[]|\\&|g'; } +glob_quote () { printf "%s" "$1" | sed 's|[\\?*[]]|\\&|g'; } + PATTERN="" COMPLETE_WORD=0 FIND_FILE_LIMIT=1000 @@ -26,7 +29,9 @@ while [ $# -gt 0 ]; do done if [ $COMPLETE_WORD = 1 ]; then - tr -cs '[:alnum:]_' '\n' | grep "^$PATTERN." | sort -u + tr -cs '[:alnum:]_' '\n' | + grep "^$(basic_regex_quote "$PATTERN")." | + sort -u else case $PATTERN in /*) @@ -41,7 +46,7 @@ else START=$(dirname "$PATTERN") find "$START" \ ! -path '*/\.*' \ - -a -path "$PATTERN*" 2>/dev/null | + -a -path "$(glob_quote "$PATTERN")*" 2>/dev/null | head -n $FIND_FILE_LIMIT | sort fi |