ellipsis-direnv/ellipsis.sh
2023-04-18 18:15:51 -04:00

114 lines
2.1 KiB
Bash

#!/usr/bin/env bash
#
# direnv 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
Darwin)
kernel=macOS
;;
esac
case "$(uname -m)" in
x86_64)
machine=amd64
;;
i686 | i386)
machine=386
;;
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_github_release () {
local repo=$1
local pattern=$2
local version=${3-}
if [[ -n "${version:-}" ]] && [[ "$version" != 'latest' ]]; then
gh_url_suffix="tags/${version}"
else
gh_url_suffix="latest"
fi
download_url=$(
curl -fL "https://api.github.com/repos/$repo/releases/$gh_url_suffix" \
| grep browser_download_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() {
set -x
local bin=direnv
# Fetch archive
if ! fs.file_exists $PKG_PATH/$bin; then
local download_url= kernel= machine=
eval "$(detect_platform)"
download_url=$(get_github_release direnv/direnv "direnv.$kernel-$machine" latest)
curl -o "$PKG_PATH/$bin" -fL "$download_url"
fi
chmod +x "$bin"
set +x
}
pkg.uninstall() {
local bin=direnv
if fs.file_exists $PKG_PATH/$bin; then
rm $PKG_PATH/$bin
fi
}
pkg.link() {
local bin=direnv
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
# }