Skip to content

Instantly share code, notes, and snippets.

@emmanueltouzery
Created September 18, 2022 11:31
Show Gist options
  • Save emmanueltouzery/defb0f48a9577e3eae2ac321bb89850d to your computer and use it in GitHub Desktop.
Save emmanueltouzery/defb0f48a9577e3eae2ac321bb89850d to your computer and use it in GitHub Desktop.
nvim_plugin_versions.sh
#! /bin/bash
plugins_and_versions_raw=$(grep -P "use\s+{" "$1" -A2)
AWK=$(cat<<'EOF'
match($0, /['"]([a-zA-Z\-_0-9\.]+\/[a-zA-Z\-_0-9\.]+)['"]/, res) {repo=res[1]}
match($0, /commit[[:space:]]*=[[:space:]]*.([^'"]+)./, res) {commit=res[1]; printf("%s#%s\n", repo, commit)}
EOF
)
plugins_and_versions=$(echo "$plugins_and_versions_raw" | awk "$AWK")
for plugin in $plugins_and_versions; do
vars=(${plugin//#/ })
repo="${vars[0]}"
commit="${vars[1]}"
# https://stackoverflow.com/a/27899728/516188
commits=$(curl -sS "https://api.github.com/repos/$repo/commits?per_page=100" | jq -r '.[] | .sha')
# echo "Fetched $(echo "$commits" | wc -l) commits"
commits_behind_plus_one=$(echo "$commits" | grep -n "$commit" | sed "s/:.*//")
commits_behind=$(expr "$commits_behind_plus_one" - 1)
echo "$repo: $commits_behind commits behind"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment