aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Allen <screwtape@froup.com>2016-10-06 19:09:53 +1100
committerTim Allen <screwtape@froup.com>2016-10-07 19:53:55 +1100
commit626991abc89a86ff1ea851b4ccae6801b323223c (patch)
tree8fb90452553ef733b89cd4953a3940b58c5ba3b4
parent4e8e356e94533cc2d47aec804cdc86dbb0fca530 (diff)
downloadvis-626991abc89a86ff1ea851b4ccae6801b323223c.tar.gz
vis-626991abc89a86ff1ea851b4ccae6801b323223c.tar.xz
Don't use repeated shell evaluation in vis-complete.
Previously, vis-complete built up a command-line by repeated subtitution into a shell variable, then executing that shell variable in a subshell. I'm not entirely sure what shell-meta-character mischief would have been possible, but now we just do all the piping in the same shell which is much safer.
-rwxr-xr-xvis-complete14
1 files changed, 3 insertions, 11 deletions
diff --git a/vis-complete b/vis-complete
index 3a2d97b..278bf40 100755
--- a/vis-complete
+++ b/vis-complete
@@ -25,16 +25,8 @@ while [ $# -gt 0 ]; do
esac
done
-PATTERN="$(echo "$PATTERN" | sed "s/'/'\\\\''/g")"
-
if [ $COMPLETE_WORD = 1 ]; then
- CMD=$(printf "tr -cs '[:alnum:]_' '\n' | grep '^%s.' | sort -u" "$PATTERN")
+ tr -cs '[:alnum:]_' '\n' | grep "^$PATTERN." | sort -u
else
- CMD=$(printf "find . ! -path '*/\.*' -a -path './%s*' 2>/dev/null | head -n $FIND_FILE_LIMIT | cut -b 3- | sort" "$PATTERN")
-fi
-
-PATTERN="$(echo "$PATTERN" | sed 's:/:\\/:g')"
-
-CMD=$(printf "$CMD | vis-menu -b | sed 's/^%s//' | tr -d '\n'" "$PATTERN")
-
-exec /bin/sh -c "$CMD"
+ find . ! -path '*/\.*' -a -path "./$PATTERN*" 2>/dev/null | head -n $FIND_FILE_LIMIT | cut -b 3- | sort
+fi | vis-menu -b | sed "s/^$(printf "%s" "$PATTERN" | sed 's:/:\\/:g' )//" | tr -d '\n'