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}" $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 () { extract_tarball () {
url="${1}" url="${1}"
dest="${2}" dest="${2}"

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

Loading…
Cancel
Save