2 # Desc: Grep search filenames of all git committed work trees 
   3 # Usage: git-bk-find-file [string regex] 
   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 
  31     # Decide if need to show commit at all 
  32     if results
="$(git ls-tree -r --name-only "$commit" | grep "$1")"; then 
  33         commit
="${commit:(-8)}"; # get last 8 chars 
  34         # Prepend results with commit 
  35         results
="$( echo "$results" | sed "s
/^
/$commit: /" )"; 
  36         printf "%s\n" "$results"; 
  44     export -f yell die must display_commit
; 
  45     git rev-list 
--all | parallel 
--jobs=75% display_commit 
"{}" "$@"; 
  50 # Author: Steven Baltakatei Sandoval