aboutsummaryrefslogtreecommitdiff
path: root/vis-complete
diff options
context:
space:
mode:
authorTwoFinger <Two-Finger@users.noreply.github.com>2018-01-25 20:13:23 +0200
committerTwoFinger <Two-Finger@users.noreply.github.com>2018-01-27 13:06:53 +0200
commite9c915335b162f05ad5246c166faa055a240118e (patch)
treee9062139a1e8344f5bd0e98756451abea4bf2c42 /vis-complete
parent5963289d0257c7bd422c3cf54866a846168f5c7a (diff)
downloadvis-e9c915335b162f05ad5246c166faa055a240118e.tar.gz
vis-e9c915335b162f05ad5246c166faa055a240118e.tar.xz
vis-complete: Slight refactoring
Move the "case $PATTERN" block inside "if $COMPLETE_WORD" to make it clear that it is specific only to the "else" branch. Eliminate the $START variable - it was used only once, and using dirname(1) directly is obvious enough. Remove the comments inside the "case" block (explaining the "what") and replaced them with a single comment explaining the "why".
Diffstat (limited to 'vis-complete')
-rwxr-xr-xvis-complete19
1 files changed, 7 insertions, 12 deletions
diff --git a/vis-complete b/vis-complete
index 398244f..255958d 100755
--- a/vis-complete
+++ b/vis-complete
@@ -28,32 +28,27 @@ while [ $# -gt 0 ]; do
esac
done
-if [ $COMPLETE_WORD = 0 ]; then
+if [ $COMPLETE_WORD = 1 ]; then
+ tr -cs '[:alnum:]_' '\n' |
+ grep "^$(basic_regex_quote "$PATTERN")." |
+ sort -u
+else
+ # Expand to absolute path because of the -path option below.
case $PATTERN in
/*)
- # An absolute path. This is fine.
;;
'~'|'~/'*)
- # Expand tilde to $HOME
PATTERN=$HOME$(echo $PATTERN | tail -c +2)
;;
*)
- # A relaive path. Let's make it absolute.
PATTERN=$PWD/$PATTERN
;;
esac
-fi
-if [ $COMPLETE_WORD = 1 ]; then
- tr -cs '[:alnum:]_' '\n' |
- grep "^$(basic_regex_quote "$PATTERN")." |
- sort -u
-else
- START=$(dirname "$PATTERN")
# The first path condition rules out paths that start with "." unless
# they start with "..". That way, hidden paths should stay hidden, but
# non-normalised paths should still show up.
- find "$START" \
+ find $(dirname "$PATTERN") \
-name '.*' -prune \
-o \( \
! -name '.*' \