I am working on making a git command I use more useful. A common task I do is to grep
my git rev-list --all
. I wrote (aka cut and pasted another StackExchange answer) git command to do this for me.
~/bin/git-search
:
!/bin/bash
function _search() {
git rev-list --all | (
while read revision; do
git grep -F $1 $revision
done
)
}
_search $1
The output from this looks like:
f26ce56cf6b17401292c494f906b2b6a9071ca75:filename.py:grepped string
I usually take these results and run git show
along with the commit and file path to see that particular version of the file. git show
takes the input of {COMMIT HASH}:path/to/file
.
What I'd ideally like is to have my git function stick a whitespace where the second :
is, which would allow me more easily copy and paste the output of git-search
into git show
, ie:
f26ce56cf6b17401292c494f906b2b6a9071ca75:filename.py grepped string
I'd like to use BASH for this as I am already using BASH. My initial solution was to use Python but that seems needless to me. I just am not sure how best to achieve this in BASH.