diff --git a/tmux-thumbs-install.sh b/tmux-thumbs-install.sh index 2bd4cde..14e625c 100755 --- a/tmux-thumbs-install.sh +++ b/tmux-thumbs-install.sh @@ -22,34 +22,53 @@ 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. Remember that Rust is -a prerequisite to being able to build tmux-thumbs. +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 -read -s -n 1 +read -rs -n 1 if ! [ -x "$(command -v cargo)" ]; then - echo 'Rust is not installed! ❌' >&2 - echo 'Press any key to install it' >&2 + platform="$(uname -s) $(uname -m)" - read -s -n 1 + echo "Rust is not installed! Trying to install ${platform} binary..." - # This installation es provided by the official https://rustup.rs documentation - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + sources=$(curl -s "https://api.github.com/repos/fcsonline/tmux-thumbs/releases/latest" | grep browser_download_url) + + case $platform in + "Darwin x86_64") + url=$(echo "${sources}" | grep -o 'https://.*darwin.zip' | uniq) + curl -L "${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 + + ;; + *) + echo "Unknown platform: $platform" + exit 1 + ;; + esac + + chmod +x thumbs tmux-thumbs + mkdir -p target/release + mv thumbs target/release + mv tmux-thumbs target/release +else + echo 'Compiling tmux-thumbs, be patient:' + cargo build --release --target-dir=target fi -echo 'Compiling tmux-thumbs, be patient:' - -cargo build --release --target-dir=target - cat << EOF Installation complete! 💯 Press any key to close this pane... EOF -read -s -n 1 +read -rs -n 1 diff --git a/tmux-thumbs.sh b/tmux-thumbs.sh index 83255d3..81f98b2 100755 --- a/tmux-thumbs.sh +++ b/tmux-thumbs.sh @@ -3,16 +3,12 @@ set -Eeu -o pipefail # 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" -if [ -d ${CURRENT_DIR}/.git ]; then - RELEASE_DIR="${CURRENT_DIR}/target/release" -else - RELEASE_DIR=${CURRENT_DIR} -fi +THUMBS_BINARY="${RELEASE_DIR}/thumbs" +TMUX_THUMBS_BINARY="${RELEASE_DIR}/tmux-thumbs" -BINARY="${RELEASE_DIR}/thumbs" - -if [ ! -f "$BINARY" ]; then +if [ ! -f "$THUMBS_BINARY" ]; then tmux split-window "cd ${CURRENT_DIR} && bash ./tmux-thumbs-install.sh" exit fi @@ -50,4 +46,4 @@ add-param upcase-command string add-param multi-command string add-param osc52 boolean -"${RELEASE_DIR}/tmux-thumbs" "${PARAMS[@]}" || true +"${TMUX_THUMBS_BINARY}" "${PARAMS[@]}" || true