Skip to content

Instantly share code, notes, and snippets.

@mizlan
Last active June 24, 2021 18:33
Show Gist options
  • Save mizlan/50ea7fadbc9b016eae87d6522cb771ab to your computer and use it in GitHub Desktop.
Save mizlan/50ea7fadbc9b016eae87d6522cb771ab to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# use like:
# ~/treesitter_neovim_bonker.sh /path/to/tree-sitter/repo /path/to/neovim/repo
# you need to use git-bisect on the tree-sitter repository before doing this
TREE_SITTER_DIR=$1
NEOVIM_DIR=$2
# GNU sed, please!
sed_cmd=gsed
# GNU grep, please!
grep_cmd=ggrep
# replace the commit of tree-sitter on Neovim
ts_commit_hash="$(cd $TREE_SITTER_DIR && git rev-parse HEAD)"
printf 'the TS commit hash is %s\n' $ts_commit_hash
$sed_cmd -i -E "s#(TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/)[a-f0-9]*(\.zip)#\1$ts_commit_hash\2#; s#(TREESITTER_SHA256 )[a-f0-9]*#\1#" \
$NEOVIM_DIR/third-party/CMakeLists.txt
printf 'modified third-party/CMakeLists.txt\n'
correct_checksum="$(cd $NEOVIM_DIR && make 2>&1 | $grep_cmd -P -o -m 1 "[a-f0-9]+(?= instead)")"
printf 'correct checksum is %s\n' $correct_checksum
$sed_cmd -i -E "s#(TREESITTER_SHA256 )#\1$correct_checksum#" \
$NEOVIM_DIR/third-party/CMakeLists.txt
cd $NEOVIM_DIR && make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment