aboutsummaryrefslogtreecommitdiff
path: root/vis-complete
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-09-25 10:57:01 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-09-25 11:53:12 +0200
commitc3bbd835fca0ba184f191b270d9aebfc2466be82 (patch)
tree956502573e1e83d7bf39ec04c11cb8c1131a413c /vis-complete
parentd3798ba58d3f8ebef9a024c8d538d7bebb0b6931 (diff)
downloadvis-c3bbd835fca0ba184f191b270d9aebfc2466be82.tar.gz
vis-c3bbd835fca0ba184f191b270d9aebfc2466be82.tar.xz
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
Diffstat (limited to 'vis-complete')
-rwxr-xr-xvis-complete35
1 files changed, 35 insertions, 0 deletions
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"