1
0
mirror of https://github.com/dcarrillo/dotfiles.git synced 2025-07-04 15:49:25 +00:00

[neovim] Add auto-replace to check_plugin_updates.sh

This commit is contained in:
2022-10-07 19:31:01 +02:00
parent 1ebdd0846c
commit 893b6e0b7b
2 changed files with 20 additions and 11 deletions

View File

@ -4,12 +4,16 @@
# Best effort script to check whenever a plugin pinned by commit has updates.
# plugins.lua must be formatted with stylua before running the script.
#
# Add flag --update to replace the commit id by the latest one
#
#
PLUGINS_DIR="$HOME/.local/share/nvim/site/pack/packer/start"
function check_update() {
local plugin=$1
local current_commit=$2
local update=${3:-"false"}
local last_commit
local remote_url
@ -18,6 +22,10 @@ function check_update() {
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"
if [[ $update == "--update" ]]; then
sed -i "s/$current_commit/$last_commit/" "$HOME/.config/nvim/lua/user/plugins.lua"
fi
else
echo "Plugin $plugin is up to date."
fi
@ -25,23 +33,24 @@ function check_update() {
popd > /dev/null || exit
}
update=${1:-"false"}
pushd "$HOME/.config/nvim/lua/user" > /dev/null || exit
grep -P "use.*commit" plugins.lua | cut -f 2,4 -d "\"" | while IFS= read -r line; do
plugin=$(echo "$line" | cut -f1 -d "\"" | cut -f2 -d "/")
current_commit=$(echo "$line" | cut -f2 -d "\"")
check_update "$plugin" "$current_commit"
check_update "$plugin" "$current_commit" "$update"
done
grep -P "^\t*commit" plugins.lua | cut -f2 -d "\"" | while IFS= read -r current_commit; do
plugin=$(grep "$current_commit" -B1 plugins.lua | grep -v "$current_commit" | cut -f2 -d "\"" | cut -f2 -d "/")
check_update "$plugin" "$current_commit"
check_update "$plugin" "$current_commit" "$update"
done
grep -P "^\t*requires.*commit" plugins.lua | cut -f 2,4 -d "\"" | while IFS= read -r line; do
plugin=$(echo "$line" | cut -f1 -d "\"" | cut -f2 -d "/")
current_commit=$(echo "$line" | cut -f2 -d "\"")
check_update "$plugin" "$current_commit"
check_update "$plugin" "$current_commit" "$update"
done
popd > /dev/null || exit