Skip to content

Commit

Permalink
style: fix style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ilvez committed Dec 29, 2024
1 parent a94fd17 commit 348093a
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,71 @@ TOOL_NAME="ghostty"
TOOL_TEST="ghostty --version"

fail() {
echo -e "asdf-$TOOL_NAME: $*"
exit 1
echo -e "asdf-$TOOL_NAME: $*"
exit 1
}

curl_opts=(-fsSL)

# NOTE: You might want to remove this if ghostty is not hosted on GitHub releases.
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
fi

sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}

list_github_tags() {
git ls-remote --tags --refs "$GH_REPO" |
grep -o 'refs/tags/.*' | cut -d/ -f3- |
sed 's/^v//' # NOTE: You might want to adapt this sed to remove non-version strings from tags
git ls-remote --tags --refs "$GH_REPO" |
grep -o 'refs/tags/.*' | cut -d/ -f3- |
sed 's/^v//' # NOTE: You might want to adapt this sed to remove non-version strings from tags
}

list_all_versions() {
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# Change this function if ghostty has other means of determining installable versions.
list_github_tags
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# Change this function if ghostty has other means of determining installable versions.
list_github_tags
}

download_release() {
local version filename url
version="$1"
filename="$2"

if [ "$version" == "tip" ]; then
url="$GH_REPO/archive/refs/tags/${version}.tar.gz"
else
url="$GH_REPO/archive/refs/tags/v${version}.tar.gz"
fi

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
local version filename url
version="$1"
filename="$2"

if [ "$version" == "tip" ]; then
url="$GH_REPO/archive/refs/tags/${version}.tar.gz"
else
url="$GH_REPO/archive/refs/tags/v${version}.tar.gz"
fi

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
}

install_version() {
local install_type="$1"
local version="$2"
local install_path="$3"
local install_type="$1"
local version="$2"
local install_path="$3"

if [ "$install_type" != "version" ]; then
fail "asdf-$TOOL_NAME supports release installs only"
fi
if [ "$install_type" != "version" ]; then
fail "asdf-$TOOL_NAME supports release installs only"
fi

(
cd $ASDF_DOWNLOAD_PATH && zig build -Doptimize=ReleaseFast
(
cd $ASDF_DOWNLOAD_PATH && zig build -Doptimize=ReleaseFast

mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/zig-out/* "$install_path"
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/zig-out/* "$install_path"

local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/bin/$tool_cmd" || fail "Expected $install_path/bin/$tool_cmd to be executable."
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/bin/$tool_cmd" || fail "Expected $install_path/bin/$tool_cmd to be executable."

echo "$TOOL_NAME $version installation was successful!"
) || (
rm -rf "$install_path"
fail "An error occurred while installing $TOOL_NAME $version."
)
echo "$TOOL_NAME $version installation was successful!"
) || (
rm -rf "$install_path"
fail "An error occurred while installing $TOOL_NAME $version."
)
}

0 comments on commit 348093a

Please sign in to comment.