Update install-bat-home script to include bat-extras

main
Buddy Sandidge 4 years ago
parent 7589cdf19f
commit 465f393a32

@ -53,6 +53,39 @@ set_current_link () {
$sudo ln -s "$rel" "${current}"
}
unlink_if_set () {
dir="$1"
if [ -L "${dir}" ]; then
unlink "${dir}"
fi
}
mkdir_if_missing () {
dir="$1"
if [ ! -d "${dir}" ]; then
mkdir -p "${dir}"
fi
}
extract_zip () {
url="${1}"
dest="${2}"
args="${3}"
sudo="${4}"
if [ -d "${dest}" ]; then
return
fi
$sudo mkdir -p "${dest}"
tmp_dir="$(mktemp -d)"
zipfile=${tmp_dir}/release.zip
curl --silent --location --output "${zipfile}" "${url}"
# shellcheck disable=SC2086
$sudo unzip -o "${zipfile}" -d "${dest}" ${args}
rm -rf "${tmp_dir}"
}
extract_tarball () {
url="${1}"
dest="${2}"

@ -1,9 +1,17 @@
#!/usr/bin/env bash
# shellcheck disable=SC1090
source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh"
APP=bat
VERSION=${VERSION:-v0.17.1}
DATA_DIR="${XDG_DATA_HOME}/apps/releases"
DEST_DIR="${DATA_DIR}/${APP}/${VERSION}"
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=
@ -22,50 +30,44 @@ case $(uname -m) in
*) >&2 echo "unsupported architecture: $(uname -m)"; exit 1;;
esac
function bail () {
echo "unexpected error $1"
exit 1
}
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"
function do_link () {
local dir="$1"
local link="$2"
if [[ ! -d "${dir}" ]] ; then
return
fi
if [[ -L "${dir}/$(basename "${link}")" ]] ; then
return
fi
cd "${dir}" || bail "failed to change directory: ${dir}"
ln --symbolic "${link}" "$(basename "${link}")"
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
}
URL="https://github.com/sharkdp/bat/releases/download/${VERSION}/bat-${VERSION}-${ARCH}-${OS}.tar.gz"
TMP_DIR=
if [[ ! -d "${DEST_DIR}" ]] ; then
set -x
TMP_DIR=$(mktemp --directory)
TAR_GZ="${TMP_DIR}/release.tar.gz"
echo "start download: ${URL}"
curl --location --silent --output "${TAR_GZ}" "${URL}"
echo "stop download: ${URL}"
mkdir -p "${DEST_DIR}"
tar xzf "${TAR_GZ}" --strip-components 1 --directory "${DEST_DIR}"
rm -rf "${TMP_DIR}"
fi
unset TMP_DIR
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}"
cd "${DATA_DIR}/${APP}" || bail "directory change failed: ${DATA_DIR}/${APP}"
[[ -s current ]] && unlink current
ln -s "${VERSION}" current
for file_path in "${EXTRA_CURRENT}"/bin/*; do
file=$(basename "${file_path}")
set_symlink "${XDG_BIN_HOME}" "${file}" "${EXTRA_CURRENT}/bin" "${file}"
done
# TODO: get the completion working
#ZSH_CONFIG_D="${XDG_CONFIG_HOME}/zsh/zshrc.d"
#FISH_CONFIG_D="${XDG_CONFIG_HOME}/fish/functions"
MAN_DIR="${XDG_DATA_HOME}/man/man1"
[[ -d ${MAN_DIR} ]] || mkdir -p "${MAN_DIR}"
for file_path in "${EXTRA_CURRENT}"/man/*; do
file=$(basename "${file_path}")
set_symlink "${MAN_DIR}" "${file}" "${EXTRA_CURRENT}/man" "${file}"
done
do_link "${XDG_BIN_HOME}" "${DATA_DIR}/${APP}/current/bat"
#do_link "${ZSH_CONFIG_D}" "${DATA_DIR}/${APP}/current/autocomplete/bat.zsh"
#do_link "${FISH_CONFIG_D}" "${DATA_DIR}/${APP}/current/autocomplete/bat.fish"
do_link "${MAN_DIR}" "${DATA_DIR}/${APP}/current/bat.1"
for file_path in "${EXTRA_CURRENT}"/doc/*; do
file=$(basename "${file_path}")
set_symlink "${XDG_DATA_HOME}/doc" "${file}" "${EXTRA_CURRENT}/doc" "${file}"
done

Loading…
Cancel
Save