1
0

update-treesitter.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env bash
  2. # shellcheck disable=SC2016
  3. set -euo pipefail
  4. treesitter_rev=$(jq -r '.["nvim-treesitter/nvim-treesitter"].rev' ../plugins/sources.json)
  5. lockfile=$(curl -L -sf "https://github.com/nvim-treesitter/nvim-treesitter/raw/$treesitter_rev/lockfile.json")
  6. grammars=$(< grammars.json)
  7. get_revision() {
  8. jq -r ".$1.revision" <<<"$lockfile"
  9. }
  10. q() {
  11. jq -r "$@" <<<"$grammars"
  12. }
  13. u() {
  14. grammars=$(jq "$@" <<<"$grammars")
  15. }
  16. update_grammar() {
  17. name=$1
  18. repo=$(q --arg name "$name" '.[$name].repo // "tree-sitter/tree-sitter-\($name)"')
  19. echo "Updating $name" >&2
  20. revision=$(get_revision "$name")
  21. if branch=$(q -e --arg name "$name" '.[$name].branch'); then
  22. revision=$(git ls-remote "https://github.com/$repo" "$branch" | cut -b -40)
  23. fi
  24. sha256=$(nix-prefetch-url --unpack "https://github.com/$repo/archive/$revision.tar.gz")
  25. u --arg name "$name" --arg rev "$revision" --arg sha256 "$sha256" '
  26. .[$name] = (.[$name] // {}) * {
  27. rev: $rev,
  28. sha256: $sha256,
  29. }
  30. '
  31. }
  32. update_all() {
  33. for grammar in $(q 'to_entries | .[] | .key'); do
  34. update_grammar "$grammar"
  35. done
  36. }
  37. if [ "$#" -eq 0 ]; then
  38. update_all
  39. else
  40. while [ "$#" -gt 0 ]; do
  41. update_grammar "$1"
  42. shift
  43. done
  44. fi
  45. echo "$grammars" > grammars.json