Add a new flow to detect plugin updates

If you update the plugin with TPM, the `thumbs` binary can get out of
sync. So we need to check the version before proceed.

If there is a version mismatch, then we run a new install in "update"
mode.
This commit is contained in:
Ferran Basora 2022-02-01 21:50:31 +00:00
parent db2a8896c9
commit 3b210d5631
3 changed files with 46 additions and 19 deletions

View File

@ -75,6 +75,8 @@ You can add this line to your list of [TPM](https://github.com/tmux-plugins/tpm)
```
set -g @plugin 'fcsonline/tmux-thumbs'
run-shell ~/.tmux/plugins/tmux-thumbs/tmux-thumbs.tmux
```
To be able to install the plugin just hit <kbd>prefix</kbd> + <kbd>I</kbd>. You should now be able to use

View File

@ -17,8 +17,27 @@ cat << EOF
░░█████ █████░███ █████ ░░████████ █████ █████ ░░█████ ████ █████ ░░████████ █████░███ █████ ████████ ██████
░░░░░ ░░░░░ ░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░ ░░░░░ ░░░░░░░░ ░░░░░░
EOF
if [ "${1:-install}" == "update" ]; then
cat << EOF
⚠️ UPDATE! ⚠️
It looks like you got a new version of tmux-thumbs repository but
the binary version is not in sync.
We are going to proceed with the new installation.
Do you want to continue?
Press any key to continue...
EOF
else
cat << EOF
It looks like this is the first time you are executing tmux-thumbs
because the binary is not present.
@ -30,6 +49,8 @@ Do you want to continue?
Press any key to continue...
EOF
fi
read -rs -n 1
if ! [ -x "$(command -v cargo)" ]; then
@ -42,12 +63,12 @@ if ! [ -x "$(command -v cargo)" ]; then
case $platform in
"Darwin x86_64")
url=$(echo "${sources}" | grep -o 'https://.*darwin.zip' | uniq)
curl -L "${url}" | bsdtar -xf - thumbs tmux-thumbs
curl -sL "${url}" | bsdtar -xf - thumbs tmux-thumbs
;;
"Linux x86_64")
url=$(echo "${sources}" | grep -o 'https://.*linux-musl.tar.gz' | uniq)
curl -L "${url}" | tar -zxf - thumbs tmux-thumbs
curl -sL "${url}" | tar -zxf - thumbs tmux-thumbs
;;
*)
@ -58,8 +79,7 @@ if ! [ -x "$(command -v cargo)" ]; then
chmod +x thumbs tmux-thumbs
mkdir -p target/release
mv thumbs target/release
mv tmux-thumbs target/release
mv thumbs tmux-thumbs target/release
else
echo ' Compiling tmux-thumbs, be patient:'
cargo build --release --target-dir=target

View File

@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -Eeu -o pipefail
VERSION=$(grep 'version =' Cargo.toml | grep -oe "[0-9]\+.[0-9]\+.[0-9]\+")
# Setup env variables to be compatible with compiled and bundled installations
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
RELEASE_DIR="${CURRENT_DIR}/target/release"
@ -11,6 +13,9 @@ TMUX_THUMBS_BINARY="${RELEASE_DIR}/tmux-thumbs"
if [ ! -f "$THUMBS_BINARY" ]; then
tmux split-window "cd ${CURRENT_DIR} && bash ./tmux-thumbs-install.sh"
exit
elif [[ $(${THUMBS_BINARY} --version) != "thumbs ${VERSION}" ]]; then
tmux split-window "cd ${CURRENT_DIR} && bash ./tmux-thumbs-install.sh update"
exit
fi
function get-opt-value() {