#!/usr/bin/env bash # # glab ellipsis package ELLIPSIS_SHELL_BIN="$HOME/.local/bin" ELLIPSIS_SHELL_HOME="$HOME/.local/shell" detect_platform() { local kernel= machine= kernel=$(uname -s | tr "[:upper:]" "[:lower:]") case "${kernel}" in linux) kernel=Linux ;; Darwin) kernel=macOS ;; esac case "$(uname -m)" in x86_64) machine=x86_64 ;; i686 | i386) machine=i386 ;; aarch64 | arm64) machine=arm64 ;; *) >&2 echo "Machine $(uname -m) not supported by the installer.\n" \ "Go to https://direnv for alternate installation methods." return 1 ;; esac echo "machine='$machine'; kernel='$kernel';" } get_gitlab_release () { local repo=$1 local pattern=$2 local version=${3:-latest} if [[ -n "${version:-}" ]]; then gh_url_suffix="tags/${version}" else gh_url_suffix="latest" fi download_url=$( curl -fL "https://gitlab.com/api/v4/projects/$repo/releases?order_by=released_at" \ | sed 's/,/,\n/g' \ | grep -w url \ | cut -d '"' -f 4 \ | grep "$pattern" ) if [[ "$version" == 'latest' ]]; then echo "$download_url" | head -n 1 else echo "$download_url" | grep "$version" | head -n 1 fi } # The following hooks can be defined to customize behavior of your package: pkg.install() { local bin=glab local archive=glab.tar.gz # Fetch archive if ! fs.file_exists $PKG_PATH/$archive; then local download_url= kernel= machine= eval "$(detect_platform)" download_url=$(get_gitlab_release 34675721 "${kernel}_${machine}.tar.gz" latest) curl -o "$PKG_PATH/$archive" -fL "$download_url" fi # Extract binary local binary=$(tar -tf "$PKG_PATH/glab.tar.gz" | grep bin/glab) local components="${binary//[^\/]}" components=${#components} tar --extract \ --file="$PKG_PATH/$archive" \ --directory "$PKG_PATH" \ --strip-components=$components \ $binary chmod +x glab } pkg.uninstall() { local bin=glab if fs.file_exists $PKG_PATH/$bin; then rm $PKG_PATH/$bin # rm $ELLIPSIS_SHELL_BIN/$bin fi } pkg.link() { local bin=glab if ! fs.file_exists $PKG_PATH/$bin; then pkg.install fi fs.link_rfile $bin $ELLIPSIS_SHELL_BIN/$bin } # pkg.push() { # git.push # } # pkg.pull() { # git.pull # } # pkg.installed() { # git.status # } # # pkg.status() { # git.diffstat # }