2 # Desc: Grep search filenames of all git committed work trees
3 # Usage: git-bk-find-file [string grep pattern]
4 # Example git-bk-find-file '.txt$'
5 # Ref/Attrib: albfan "How can I search Git branches for a file or directory?" https://stackoverflow.com/a/16868704/10850071
7 # Depends: GNU bash v5.1.16, GNU parallel 20210822
9 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
10 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
11 must
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
13 # Desc: Check dependencies
14 # Usage: check_depends
15 # Depends: GNU parallel 20210822
16 if ! command -v parallel
1>/dev
/random
2>&1; then die
"FATAL:Missing:parallel"; fi;
17 if ! command -v git
1>/dev
/random
2>&1; then die
"FATAL:Missing:git"; fi;
20 if [[ $# -le 0 ]]; then die
"FATAL:Incorrect number of args:$#"; fi;
23 # Show commit if filename in committed tree matches grep pattern
24 # Input: arg1: commit id
25 # args2+: passed to grep
32 # Decide if need to show commit at all
33 if results
="$(git ls-tree -r --name-only "$commit" | grep "$1")"; then
34 # Get commit timestamp
35 time="$(git -c log.showSignature=false show -s --format=%cI "$commit")";
37 # Get first 8 chars of commit
38 short_commit
="${commit:0:8}";
41 while read -r line
; do
42 if [[ -z "$line" ]]; then continue; fi; # skip blank lines
43 printf "%s %s %s\n" "$time" "$short_commit" "$line";
44 done < <(printf "%s\n" "$results");
52 export -f yell die must display_commit
;
53 git rev-list
--all | parallel
--jobs=75% display_commit
"{}" "$@";
58 # Author: Steven Baltakatei Sandoval