2021-12-06 22:35:29 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#!nix-shell update-shell.nix -i bash
|
|
|
|
|
2021-12-15 23:27:07 +00:00
|
|
|
set -eEuo pipefail
|
|
|
|
|
|
|
|
current_command='none'
|
|
|
|
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
|
|
|
|
trap 'code=$?; if [ "$code" -ne "0" ]; then echo "\"${last_command}\" command ended with exit code $code."; fi' EXIT
|
2021-12-15 19:43:52 +00:00
|
|
|
|
2021-12-06 22:35:29 +00:00
|
|
|
script_dir="$(dirname "$(realpath "$0")")"
|
|
|
|
plugins="${script_dir}/plugins.txt"
|
|
|
|
nix_new_file="${script_dir}/plugins_new.nix"
|
|
|
|
nix_file="${script_dir}/plugins.nix"
|
|
|
|
|
2021-12-15 19:43:52 +00:00
|
|
|
github_auth="$(cat "${script_dir}/github.auth")"
|
|
|
|
|
|
|
|
rm -f "$nix_new_file"
|
2021-12-07 08:05:54 +00:00
|
|
|
echo '# This file has been auto-generated' >"$nix_new_file"
|
|
|
|
echo '{ pkgs, ... }:' >>"$nix_new_file"
|
2021-12-06 22:35:29 +00:00
|
|
|
|
2021-12-07 08:05:54 +00:00
|
|
|
echo "{" >>"$nix_new_file"
|
2021-12-06 22:35:29 +00:00
|
|
|
while IFS='' read -r LINE || [ -n "${LINE}" ]; do
|
|
|
|
owner="$(echo "$LINE" | cut -d'/' -f1)"
|
|
|
|
repo="$(echo "$LINE" | cut -d'/' -f2)"
|
2021-12-15 19:43:52 +00:00
|
|
|
|
|
|
|
echo "Updating ${owner}/${repo} ..."
|
|
|
|
|
2021-12-06 22:35:29 +00:00
|
|
|
build="$(echo "$LINE" | cut -d'/' -f3)"
|
|
|
|
name="$(echo "$repo" | tr [.] '-')"
|
2021-12-07 08:05:54 +00:00
|
|
|
src="$(nix-prefetch-github --nix --no-fetch-submodules "$owner" "$repo" 2>/dev/null | tail -n +4)"
|
2021-12-06 22:35:29 +00:00
|
|
|
rev="$(echo "$src" | grep rev | cut -d '"' -f 2)"
|
2021-12-15 19:43:52 +00:00
|
|
|
commit_info="$(curl -u "$github_auth" --silent "https://api.github.com/repos/${owner}/${repo}/commits/${rev}")"
|
|
|
|
commit_date="$(echo "$commit_info" | jq -r '.commit.committer.date')"
|
2021-12-06 22:35:29 +00:00
|
|
|
|
2021-12-15 19:43:52 +00:00
|
|
|
if [[ "$commit_date" == "null" ]]; then
|
|
|
|
commit_date="$(echo "$commit_info" | jq -r '.commit.author.date')"
|
|
|
|
fi
|
|
|
|
|
|
|
|
version="$(date -d "$commit_date" "+%s")"
|
2021-12-06 22:35:29 +00:00
|
|
|
|
2021-12-07 08:05:54 +00:00
|
|
|
echo "${name} = pkgs.vimUtils.buildVimPluginFrom2Nix {" >>"$nix_new_file"
|
|
|
|
echo "pname = \"${repo}\";" >>"$nix_new_file"
|
2021-12-15 19:43:52 +00:00
|
|
|
echo "version = \"${version}\";" >>"$nix_new_file"
|
2021-12-07 08:05:54 +00:00
|
|
|
echo "src = ${src};" >>"$nix_new_file"
|
2021-12-06 22:35:29 +00:00
|
|
|
|
|
|
|
if [ -n "$build" ]; then
|
2021-12-07 08:05:54 +00:00
|
|
|
echo "buildPhase = \"${build}\";" >>"$nix_new_file"
|
2021-12-06 22:35:29 +00:00
|
|
|
fi
|
|
|
|
|
2021-12-07 08:05:54 +00:00
|
|
|
echo "meta.homepage = \"https://github.com/${owner}/${repo}\";" >>"$nix_new_file"
|
|
|
|
echo '};' >>"$nix_new_file"
|
|
|
|
done <"$plugins"
|
|
|
|
echo "}" >>"$nix_new_file"
|
2021-12-06 22:35:29 +00:00
|
|
|
|
|
|
|
nixpkgs-fmt "$nix_new_file"
|
|
|
|
|
|
|
|
if test -f "$nix_file"; then
|
2021-12-15 23:27:07 +00:00
|
|
|
set +eo pipefail
|
2021-12-07 08:05:54 +00:00
|
|
|
diff -U 2 "$nix_file" "$nix_new_file" | bat --paging=never -ldiff
|
2021-12-15 23:27:07 +00:00
|
|
|
set -eo pipefail
|
|
|
|
|
2021-12-06 22:35:29 +00:00
|
|
|
mv "$nix_new_file" "$nix_file"
|
|
|
|
else
|
|
|
|
mv "$nix_new_file" "$nix_file"
|
2021-12-15 23:27:07 +00:00
|
|
|
|
|
|
|
set +eo pipefail
|
2021-12-06 22:35:29 +00:00
|
|
|
bat --paging=never "$nix_file"
|
2021-12-15 23:27:07 +00:00
|
|
|
set -eo pipefail
|
2021-12-06 22:35:29 +00:00
|
|
|
fi
|