Skip to content

Instantly share code, notes, and snippets.

@victorboissiere
Last active April 1, 2018 21:56
Show Gist options
  • Save victorboissiere/76173655109cabc65a378d2c37c5cf00 to your computer and use it in GitHub Desktop.
Save victorboissiere/76173655109cabc65a378d2c37c5cf00 to your computer and use it in GitHub Desktop.
Quickly open files matching specific pattern
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