Last active
October 21, 2024 10:27
-
-
Save dimitris-k/75856981dab70f743de76ab42840ba8d to your computer and use it in GitHub Desktop.
A Shell scripts that checks starship repo for a newer binary version and installs it
This file contains hidden or 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
| #!/bin/bash | |
| # Will check the "starship prompt" github repo for the latest binary version | |
| # and in case a newer version exists, it will install it. Note, that the install script | |
| # will ask the user to proceed. | |
| # function to convert a string that contain a dotted version number to a string | |
| # that can be used for alphanumeric comparison. It was found in this post replies: | |
| # https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-#!/bin/bash | |
| function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } | |
| latest_version=$(curl --silent https://api.github.com/repos/starship/starship/releases/latest | \ | |
| awk -F '"' '/tag_name/{print $4}' | tr -d v) | |
| current_version=$(starship -V | awk '{print $2}') | |
| printf "current version: %s\n latest_version: %s\n" "$current_version" "$latest_version" | |
| if [ "$(version "$latest_version")" -gt "$(version "$current_version")" ]; then | |
| printf "Will update starship to version %s\n" "$latest_version" | |
| sh -c "$(curl -fsSL https://starship.rs/install.sh)" | |
| else | |
| printf "starship version %s is up to date\n" "$current_version" | |
| fi | |
| # the script passes shellcheck checks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment