From: Steven Baltakatei Sandoval Date: Thu, 2 Mar 2023 18:49:25 +0000 (+0000) Subject: feat(user/git-bk-find-file):Show ISO 8601 time along with commit X-Git-Tag: 0.8.1^0 X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/e65cf1ee23945b1115700d9d134f29a9f7ca7c95?hp=-c feat(user/git-bk-find-file):Show ISO 8601 time along with commit --- e65cf1ee23945b1115700d9d134f29a9f7ca7c95 diff --git a/user/git-bk-find-file b/user/git-bk-find-file old mode 100644 new mode 100755 index c31b31c..f4ef58e --- a/user/git-bk-find-file +++ b/user/git-bk-find-file @@ -1,9 +1,9 @@ #!/usr/bin/env bash # Desc: Grep search filenames of all git committed work trees -# Usage: git-bk-find-file [string regex] -# Example git-bk-find-file '*.txt' +# Usage: git-bk-find-file [string grep pattern] +# Example git-bk-find-file '.txt$' # Ref/Attrib: albfan "How can I search Git branches for a file or directory?" https://stackoverflow.com/a/16868704/10850071 -# Version: 0.0.1 +# Version: 0.1.0 # Depends: GNU bash v5.1.16, GNU parallel 20210822 yell() { echo "$0: $*" >&2; } # print script path and all args to stderr @@ -24,16 +24,24 @@ display_commit() { # Input: arg1: commit id # args2+: passed to grep # Output: stdout + # Depends: git 2.34.1 local commit results; commit="$1"; shift; # Decide if need to show commit at all if results="$(git ls-tree -r --name-only "$commit" | grep "$1")"; then - commit="${commit:(-8)}"; # get last 8 chars - # Prepend results with commit - results="$( echo "$results" | sed "s/^/$commit: /" )"; - printf "%s\n" "$results"; + # Get commit timestamp + time="$(git -c log.showSignature=false show -s --format=%cI "$commit")"; + + # Get last 8 chars of commit + short_commit="${commit:(-8)}"; + + # Output results + while read -r line; do + if [[ -z "$line" ]]; then continue; fi; # skip blank lines + printf "%s %s %s\n" "$time" "$short_commit" "$line"; + done < <(printf "%s\n" "$results"); fi; return 0;