#!/usr/bin/env bash # shellcheck disable=SC1090 source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh" APP=bat BAT_DEST="${XDG_DATA_HOME}/apps/releases/${APP}" BAT_CURRENT="${BAT_DEST}/current" BAT_VERSION=${BAT_VERSION:-0.18.1} EXTRA_DEST="${XDG_DATA_HOME}/apps/releases/bat-extras" EXTRA_CURRENT="${EXTRA_DEST}/current" EXTRA_VERSION=${EXTRA_VERSION:-2021.04.06} MAN_DIR=${XDG_DATA_HOME}/man/man1 OS= ARCH= case $(uname -s) in Linux*) OS=unknown-linux-gnu;; Darwin*) OS=apple-darwin;; CYGWIN_NT*|Windows_NT*) OS=pc-windows-msvc;; *) >&2 echo "unsupported os"; return; esac case $(uname -m) in amd64*|x86_64*) ARCH=x86_64;; i686*|i386*) ARCH=i686;; arm|armv7*|armv6*) ARCH=arm;; aarch64*|armv8*) ARCH=arm64;; *) >&2 echo "unsupported architecture: $(uname -m)"; exit 1;; esac BAT_URL=https://github.com/sharkdp/bat/releases/download/v${BAT_VERSION}/bat-v${BAT_VERSION}-${ARCH}-${OS}.tar.gz EXTRA_URL="https://github.com/eth-p/bat-extras/releases/download/v${EXTRA_VERSION}/bat-extras-${EXTRA_VERSION//\./}.zip" set_symlink () { local dest_dir="$1" local dest_file="$2" local src_dir="$3" local src_file="$4" mkdir_if_missing "${dest_dir}" cd "${dest_dir}" || exit 1 unlink_if_set "${dest_dir}/${dest_file}" ln -s "$(relative_path "${dest_dir}" "${src_dir}/${src_file}")" "${dest_file}" cd - > /dev/null || exit 1 } extract_tarball "${BAT_URL}" "${BAT_DEST}/${BAT_VERSION}" "--strip-components 1" set_current_link "${BAT_DEST}" "${BAT_VERSION}" set_symlink "${XDG_BIN_HOME}" bat "${BAT_CURRENT}" bat set_symlink "${MAN_DIR}" bat.1 "${BAT_CURRENT}" bat.1 set_symlink "${XDG_CONFIG_HOME}/zsh/zshrc.d" bat-autocomplete.zsh "${BAT_CURRENT}/autocomplete" bat.zsh set_symlink "${XDG_CONFIG_HOME}/fish/functions" bat-autocomplete.fish "${BAT_CURRENT}/autocomplete" bat.fish extract_zip "${EXTRA_URL}" "${EXTRA_DEST}/${EXTRA_VERSION}" set_current_link "${EXTRA_DEST}" "${EXTRA_VERSION}" for file_path in "${EXTRA_CURRENT}"/bin/*; do file=$(basename "${file_path}") set_symlink "${XDG_BIN_HOME}" "${file}" "${EXTRA_CURRENT}/bin" "${file}" done for file_path in "${EXTRA_CURRENT}"/man/*; do file=$(basename "${file_path}") set_symlink "${MAN_DIR}" "${file}" "${EXTRA_CURRENT}/man" "${file}" done for file_path in "${EXTRA_CURRENT}"/doc/*; do file=$(basename "${file_path}") set_symlink "${XDG_DATA_HOME}/doc" "${file}" "${EXTRA_CURRENT}/doc" "${file}" done