Created
April 3, 2018 19:21
-
-
Save victorboissiere/92f9891e5f1382b1b1cf672f4fdde2f7 to your computer and use it in GitHub Desktop.
[MEDIUM] vs with autocomplete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function vs() | |
{ | |
RESULTS=`find . -type f -not -path '*/\.*' -not -path '*/vendor/*' -not -path '*/packages/*' -ipath "*$1*"` | |
red() { echo -e "\033[00;31m$1\033[0m"; } | |
NB_FILES=$(echo $RESULTS | wc -w) | |
if [ $NB_FILES -eq "1" ]; then | |
$EDITOR $(echo "$RESULTS" | head -n1 | cut -d " " -f1) | |
elif [ $NB_FILES -eq "0" ]; then | |
>&2 red "No matching file" | |
else | |
>&2 red "Error. Found more than one file" | |
column <<< "$(printf '%s\n' $RESULTS)" | |
fi | |
} | |
_vs() { | |
local curcontext="$curcontext" state line expl | |
_arguments -C \ | |
'*:: :->open_files' | |
case "$state" in | |
open_files) | |
local file=${words[CURRENT]} | |
compadd -U - `find . -type f -not -path '*/\.*' -not -path '*/vendor/*' -not -path '*/packages/*' -ipath "*$file*" | sed "s|^\./||"` | |
compstate[insert]=menu # no expand | |
;; | |
esac | |
return 0 | |
} | |
compdef _vs vs | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment