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' 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 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,37 +17,58 @@ cat << EOF
░░█████ █████░███ █████ ░░████████ █████ █████ ░░█████ ████ █████ ░░████████ █████░███ █████ ████████ ██████ ░░█████ █████░███ █████ ░░████████ █████ █████ ░░█████ ████ █████ ░░████████ █████░███ █████ ████████ ██████
░░░░░ ░░░░░ ░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░ ░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░ ░░░░░ ░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░ ░░░░░ ░░░░░░░░ ░░░░░░
It looks like this is the first time you are executing tmux-thumbs
because the binary is not present.
We are going to proceed with the installation. If you have Rust preinstalled, we will try to
compile the binary from source. Otherwise, a prebuild binary for your platform will be used.
Do you want to continue?
Press any key to continue...
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.
We are going to proceed with the installation. If you have Rust preinstalled, we will try to
compile the binary from source. Otherwise, a prebuild binary for your platform will be used.
Do you want to continue?
Press any key to continue...
EOF
fi
read -rs -n 1 read -rs -n 1
if ! [ -x "$(command -v cargo)" ]; then if ! [ -x "$(command -v cargo)" ]; then
platform="$(uname -s) $(uname -m)" platform="$(uname -s) $(uname -m)"
echo "Rust is not installed! Trying to install ${platform} binary..." echo " Rust is not installed! Trying to install ${platform} binary..."
sources=$(curl -s "https://api.github.com/repos/fcsonline/tmux-thumbs/releases/latest" | grep browser_download_url) sources=$(curl -s "https://api.github.com/repos/fcsonline/tmux-thumbs/releases/latest" | grep browser_download_url)
case $platform in case $platform in
"Darwin x86_64") "Darwin x86_64")
url=$(echo "${sources}" | grep -o 'https://.*darwin.zip' | uniq) 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") "Linux x86_64")
url=$(echo "${sources}" | grep -o 'https://.*linux-musl.tar.gz' | uniq) 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,17 +79,16 @@ if ! [ -x "$(command -v cargo)" ]; then
chmod +x thumbs tmux-thumbs chmod +x thumbs tmux-thumbs
mkdir -p target/release mkdir -p target/release
mv thumbs target/release mv thumbs tmux-thumbs target/release
mv tmux-thumbs target/release
else else
echo 'Compiling tmux-thumbs, be patient:' echo ' Compiling tmux-thumbs, be patient:'
cargo build --release --target-dir=target cargo build --release --target-dir=target
fi fi
cat << EOF cat << EOF
Installation complete! 💯 Installation complete! 💯
Press any key to close this pane... Press any key to close this pane...
EOF EOF
read -rs -n 1 read -rs -n 1

View File

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