Skip to content

Instantly share code, notes, and snippets.

@gartenfeld
Created January 9, 2016 01:26
Show Gist options
  • Select an option

  • Save gartenfeld/065a86fec571c91d2b46 to your computer and use it in GitHub Desktop.

Select an option

Save gartenfeld/065a86fec571c91d2b46 to your computer and use it in GitHub Desktop.
Search for files containing a pattern, then open those files
alias gg="git grep -n"
# -n: show line numbers
function ggl {
RESULTS=$(gg -l "$*" | tr "\n" " ");
# -l: file name (path included) only
# tr: replace $1 with $2
if [ -z "${RESULTS// }" ]; then
# "${VAR// }" removes whitespace in $VAR
# -z: not empty
echo "\e[33mNo results found.\e[0m";
else
printf $RESULTS | pbcopy;
# pipe variable into clipboard
# printf does not end in a new line like echo
echo "\e[33mList copied to clipboard.\e[0m";
echo $(pbpaste) | tr " " "\n";
fi
}
alias spb="subl $(pbpaste)"
# open a list of files in Sublime Text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment