2022-10-01 15:20:10 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# Best effort script to check whenever a plugin pinned by commit has updates.
|
|
|
|
# plugins.lua must be formatted with stylua before running the script.
|
|
|
|
#
|
2022-10-07 17:31:01 +00:00
|
|
|
# Add flag --update to replace the commit id by the latest one
|
|
|
|
#
|
|
|
|
#
|
2022-10-01 15:20:10 +00:00
|
|
|
|
|
|
|
PLUGINS_DIR="$HOME/.local/share/nvim/site/pack/packer/start"
|
2022-10-16 10:28:51 +00:00
|
|
|
CONF_DIR="$HOME/.config/nvim/lua/core/"
|
2022-10-01 15:20:10 +00:00
|
|
|
|
|
|
|
function check_update() {
|
|
|
|
local plugin=$1
|
|
|
|
local current_commit=$2
|
2022-10-07 17:31:01 +00:00
|
|
|
local update=${3:-"false"}
|
2022-10-01 15:20:10 +00:00
|
|
|
local last_commit
|
|
|
|
local remote_url
|
|
|
|
|
|
|
|
pushd "$PLUGINS_DIR/$plugin" > /dev/null || exit
|
|
|
|
last_commit=$(git log -n 1 --pretty=format:"%H" origin/HEAD)
|
|
|
|
remote_url=$(git config --get remote.origin.url)
|
|
|
|
if [[ "$current_commit" != "$last_commit" ]]; then
|
|
|
|
echo -e "Plugin $plugin has a new version $last_commit (the current version is $current_commit)\n\tURL: $remote_url"
|
2022-10-07 17:31:01 +00:00
|
|
|
|
|
|
|
if [[ $update == "--update" ]]; then
|
2022-10-16 10:28:51 +00:00
|
|
|
sed -i "s/$current_commit/$last_commit/" "$CONF_DIR/plugins.lua"
|
2022-10-07 17:31:01 +00:00
|
|
|
fi
|
2022-10-02 15:38:01 +00:00
|
|
|
else
|
|
|
|
echo "Plugin $plugin is up to date."
|
2022-10-01 15:20:10 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
popd > /dev/null || exit
|
|
|
|
}
|
|
|
|
|
2022-10-07 17:31:01 +00:00
|
|
|
update=${1:-"false"}
|
2022-10-16 10:28:51 +00:00
|
|
|
pushd "$CONF_DIR" > /dev/null || exit
|
2022-10-01 15:20:10 +00:00
|
|
|
|
2022-10-14 19:06:10 +00:00
|
|
|
grep -P "^\t*use.*commit" plugins.lua | cut -f 2,4 -d "\"" | while IFS= read -r line; do
|
2022-10-01 15:20:10 +00:00
|
|
|
plugin=$(echo "$line" | cut -f1 -d "\"" | cut -f2 -d "/")
|
|
|
|
current_commit=$(echo "$line" | cut -f2 -d "\"")
|
2022-10-07 17:31:01 +00:00
|
|
|
check_update "$plugin" "$current_commit" "$update"
|
2022-10-01 15:20:10 +00:00
|
|
|
done
|
|
|
|
|
2022-10-02 15:16:31 +00:00
|
|
|
grep -P "^\t*commit" plugins.lua | cut -f2 -d "\"" | while IFS= read -r current_commit; do
|
2022-10-01 15:20:10 +00:00
|
|
|
plugin=$(grep "$current_commit" -B1 plugins.lua | grep -v "$current_commit" | cut -f2 -d "\"" | cut -f2 -d "/")
|
2022-10-07 17:31:01 +00:00
|
|
|
check_update "$plugin" "$current_commit" "$update"
|
2022-10-01 15:20:10 +00:00
|
|
|
done
|
|
|
|
|
2022-10-02 15:16:31 +00:00
|
|
|
grep -P "^\t*requires.*commit" plugins.lua | cut -f 2,4 -d "\"" | while IFS= read -r line; do
|
2022-10-01 15:20:10 +00:00
|
|
|
plugin=$(echo "$line" | cut -f1 -d "\"" | cut -f2 -d "/")
|
|
|
|
current_commit=$(echo "$line" | cut -f2 -d "\"")
|
2022-10-07 17:31:01 +00:00
|
|
|
check_update "$plugin" "$current_commit" "$update"
|
2022-10-01 15:20:10 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
popd > /dev/null || exit
|