From 5aecb9f369a3acbaa5b386e5993d40edc1fd839a Mon Sep 17 00:00:00 2001 From: Daniel Carrillo Date: Sat, 1 Oct 2022 17:20:10 +0200 Subject: [PATCH] [neovim] Add script to check updates for plugins pinned by commitid --- .config/nvim/check_plugin_updates.sh | 45 ++++++++++++++++++++++++++++ .config/nvim/lua/user/plugins.lua | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 .config/nvim/check_plugin_updates.sh diff --git a/.config/nvim/check_plugin_updates.sh b/.config/nvim/check_plugin_updates.sh new file mode 100755 index 0000000..d88e586 --- /dev/null +++ b/.config/nvim/check_plugin_updates.sh @@ -0,0 +1,45 @@ +#!/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. +# + +PLUGINS_DIR="$HOME/.local/share/nvim/site/pack/packer/start" + +function check_update() { + local plugin=$1 + local current_commit=$2 + 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" + fi + + popd > /dev/null || exit +} + +pushd "$HOME/.config/nvim/lua/user" > /dev/null || exit + +grep -P "use.*commit" plugins.lua < 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" +done + +grep -P "^\t*commit" plugins.lua < 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" +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" +done + +popd > /dev/null || exit diff --git a/.config/nvim/lua/user/plugins.lua b/.config/nvim/lua/user/plugins.lua index cb01564..c18e06c 100644 --- a/.config/nvim/lua/user/plugins.lua +++ b/.config/nvim/lua/user/plugins.lua @@ -43,7 +43,7 @@ return packer.startup(function(use) use({ "wbthomason/packer.nvim", commit = "6afb67460283f0e990d35d229fd38fdc04063e0a" }) use({ "nvim-lua/plenary.nvim", commit = "4b7e52044bbb84242158d977a50c4cbcd85070c7" }) use({ "windwp/nvim-autopairs", commit = "14cc2a4fc6243152ba085cc2059834113496c60a" }) - use({ "numToStr/Comment.nvim", tag = "v0.6.1" }) + use({ "numToStr/Comment.nvim", tag = "v0.*" }) use({ "JoosepAlviste/nvim-ts-context-commentstring", commit = "4d3a68c41a53add8804f471fcc49bb398fe8de08" }) use({ "kyazdani42/nvim-web-devicons", commit = "563f3635c2d8a7be7933b9e547f7c178ba0d4352" }) use({ "akinsho/bufferline.nvim", tag = "v2.*" })