Last active
April 1, 2018 21:56
-
-
Save victorboissiere/76173655109cabc65a378d2c37c5cf00 to your computer and use it in GitHub Desktop.
Quickly open files matching specific pattern
This file contains 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 '*/\.*' -iname "*$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 | |
red "No matching file" | |
else | |
red "Error. Found more than one file" | |
column <<< "$(printf '%s\n' $RESULTS)" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment