Created
January 9, 2016 01:26
-
-
Save gartenfeld/065a86fec571c91d2b46 to your computer and use it in GitHub Desktop.
Search for files containing a pattern, then open those files
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
| 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