Last active
August 10, 2019 05:39
-
-
Save nikoheikkila/5292cbe28c55a7e80ceb41524042b86a to your computer and use it in GitHub Desktop.
Updates Starship to Latest Version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
post_install() { | |
# Checks whether user's shell configuration needs adjustment for Spaceship | |
# This function does not do anything when user has already activated the | |
# necessary configuration. | |
echo "Checking shell configuration" | |
if [[ "${SHELL}" =~ "bash" && $(grep -c "starship init" "${HOME}/.bashrc") -eq 0 ]]; then | |
# shellcheck disable=SC2016 | |
echo -n 'eval "$(starship init $0)"' >> "${HOME}/.bashrc" | |
echo "Bash configured." | |
return | |
fi | |
if [[ "${SHELL}" =~ "zsh" && $(grep -c "starship init" "${HOME}/.zshrc") -eq 0 ]]; then | |
# shellcheck disable=SC2016 | |
echo -n 'eval "$(starship init $0)"' >> "${HOME}/.zshrc" | |
echo "ZSH configured." | |
return | |
fi | |
if [[ "${SHELL}" =~ "fish" && $(grep -c "starship init" "${HOME}/.config/fish/config.fish") -eq 0 ]]; then | |
echo -n 'eval (starship init fish)' >> "${HOME}/.config/fish/config.fish" | |
echo "Fish configured." | |
return | |
fi | |
echo "Shell configuration OK." | |
} | |
API_URL="https://api.github.com" | |
REPO="starship/starship" | |
# Save release tarball into temporary location | |
FILENAME=$(mktemp starship.XXX.tar.gz) | |
# Save the binary here. On certain systems you might need to run this script | |
# as root user to be able to write to this location. | |
PREFIX="/usr/local/bin" | |
# Operating system to fetch the binary for. | |
OS=$(uname -s) | |
echo "Downloading latest release for ${REPO}" | |
curl -sSL -H "Accept: application/vnd.github.v3+json" -X GET "${API_URL}/repos/${REPO}/releases/latest" \ | |
| jq ".assets[].browser_download_url" \ | |
| grep -i "${OS}" \ | |
| xargs wget -qO "${FILENAME}" | |
tar xzf "${FILENAME}" -C "${PREFIX}" --strip-components=1 | |
rm -f "${FILENAME}" | |
VERSION=$(starship --version) | |
echo "Installed ${VERSION}." | |
post_install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment