Created
March 27, 2026 13:20
-
-
Save holly/78952cb28e7afa9b4dcc4d70b878a142 to your computer and use it in GitHub Desktop.
eza install
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
| #!/usr/bin/env bash | |
| set -e | |
| set -u | |
| set -o pipefail | |
| set -C | |
| REPO="eza-community/eza" | |
| BIN_NAME="eza" | |
| INSTALL_DIR="$HOME/.local/bin" | |
| BIN_PATH="$INSTALL_DIR/$BIN_NAME" | |
| CURL_ARGS=("-fsSL") | |
| if [ -n "$GITHUB_TOKEN" ]; then | |
| CURL_ARGS+=("-H" "Authorization: token $GITHUB_TOKEN") | |
| fi | |
| # アーキテクチャを判定する関数 | |
| get_arch() { | |
| local arch=$(uname -m) | |
| case $arch in | |
| x86_64) | |
| echo "x86_64" | |
| ;; | |
| aarch64 | arm64) | |
| echo "aarch64" | |
| ;; | |
| *) | |
| echo "Error: Unsupported architecture '$arch'" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| } | |
| # 現在インストールされているバージョンを取得する関数 | |
| # 出力例: v0.23.4 | |
| get_local_version() { | |
| if [ -x "$BIN_PATH" ]; then | |
| # eza - A modern, maintained replacement for ls | |
| # v0.23.4 [+git] | |
| # 上記のような出力の2行目、スペース区切り1つ目を取得 | |
| "$BIN_PATH" --version | sed -n '2p' | awk '{print $1}' | |
| fi | |
| } | |
| echo "Fetching release information from GitHub..." | |
| # GitHub APIからリリース情報を取得 | |
| JSON_DATA=$(curl "${CURL_ARGS[@]}" "https://api.github.com/repos/$REPO/releases/latest") | |
| # jqを使用してタグ名(バージョン)を取得 | |
| REMOTE_VERSION=$(echo "$JSON_DATA" | jq -r '.tag_name') | |
| if [ -z "$REMOTE_VERSION" ]; then | |
| echo "Error: Could not fetch remote version." | |
| exit 1 | |
| fi | |
| LOCAL_VERSION=$(get_local_version) | |
| if [ "$LOCAL_VERSION" = "$REMOTE_VERSION" ]; then | |
| echo "$BIN_NAME is already up to date ($LOCAL_VERSION)." | |
| exit 0 | |
| fi | |
| if [ -n "$LOCAL_VERSION" ]; then | |
| echo "Updating $BIN_NAME from $LOCAL_VERSION to $REMOTE_VERSION..." | |
| else | |
| echo "Installing $BIN_NAME $REMOTE_VERSION..." | |
| fi | |
| ARCH=$(get_arch) | |
| # jqを使用してassets配列から条件に合うURLを抽出 | |
| # 条件: 名前にアーキテクチャが含まれ、かつ "gnu.tar.gz" で終わるもの | |
| DOWNLOAD_URL=$(echo "$JSON_DATA" | jq -r --arg arch "$ARCH" \ | |
| '.assets[] | select(.name | endswith("\($arch)-unknown-linux-gnu.tar.gz")) | .browser_download_url') | |
| if [ -z "$DOWNLOAD_URL" ]; then | |
| echo "Error: Could not find a suitable download URL for architecture $ARCH (gnu, tar.gz)." | |
| exit 1 | |
| fi | |
| mkdir -p "$INSTALL_DIR" | |
| echo "Downloading from $DOWNLOAD_URL ..." | |
| # ローカルに保存せずパイプでtarに渡して展開 | |
| curl "${CURL_ARGS[@]}" "$DOWNLOAD_URL" | tar -C "$INSTALL_DIR" -xzvf - | |
| if [ -f "$BIN_PATH" ]; then | |
| chmod +x "$BIN_PATH" | |
| echo "Successfully installed $BIN_NAME to $BIN_PATH" | |
| else | |
| echo "Error: Binary not found after extraction." | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment