Skip to content

Instantly share code, notes, and snippets.

@japm48
Last active October 22, 2020 06:55
Show Gist options
  • Save japm48/1a728b589dfbd311ca13ba0126f4f50c to your computer and use it in GitHub Desktop.
Save japm48/1a728b589dfbd311ca13ba0126f4f50c to your computer and use it in GitHub Desktop.
# Requires fd: https://github.com/sharkdp/fd
gr_update_hash()
{
git status 2>/dev/null >/dev/null || { echo 'not in git repo' ; return; }
[ "$#" -ne 0 ] || { echo 'need list of args (base filenames)'; return; }
root=$(git rev-parse --show-toplevel)
fd_cmd='fd --type f --color never --max-results=1'
for f in "$@"
do
(
cd "$root"
h=$($fd_cmd "^${f}.h\$")
[ -z $h ] && { echo "$f.h not found"; return; }
ccp=$($fd_cmd "^${f}_python.cc\$")
[ -z $ccp ] && { echo "${f}_python.cc not found"; return; }
hhash=$(md5sum $h | awk '{print $1}')
echo "$f - $hhash"
sed -i -r "s/(BINDTOOL_HEADER_FILE_HASH)[(].*[)]/\1($hhash)/" "$ccp"
)
done
}
# Zero-Clause BSD (no attribution required, GPL-compatible)
# SPDX-License-Identifier: 0BSD
# Full text here: https://opensource.org/licenses/0BSD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment