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 --- vis-complete | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 vis-complete (limited to 'vis-complete') diff --git a/vis-complete b/vis-complete new file mode 100755 index 0000000..29dc457 --- /dev/null +++ b/vis-complete @@ -0,0 +1,35 @@ +#!/bin/sh +set -e + +PATTERN="" +COMPLETE_WORD=0 + +while [ $# -gt 0 ]; do + case "$1" in + -h|--help) + echo "usage: $(basename "$0") [-h] [--file|--word] [pattern]" + exit 0; + ;; + --file) + shift + ;; + --word) + COMPLETE_WORD=1 + shift + ;; + *) + PATTERN="$1" + break + ;; + esac +done + +if [ $COMPLETE_WORD = 1 ]; then + CMD=$(printf "tr -cs '[:alnum:]_' '\n' | grep '^%s.' | sort -u" "$PATTERN") +else + CMD=$(printf "find . ! -path '*/\.*' -a -path './%s*' | cut -b 3- | sort" "$PATTERN") +fi + +CMD=$(printf "$CMD | vis-menu -b | sed 's/^%s//' | tr -d '\n'" "$PATTERN") + +exec /bin/sh -c "$CMD" -- cgit v1.2.3