add: direnv config

This commit is contained in:
jez 2023-04-18 18:15:51 -04:00
parent d2cef582c7
commit 579bfd4048
3 changed files with 46 additions and 26 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
direnv

View File

@ -1,11 +1,11 @@
# user/id-mrjk # direnv
Just a bunch of dotfiles. Just a bunch of dotfiles.
## Install ## Install
Clone and symlink or install with [ellipsis][ellipsis]: Clone and symlink or install with [ellipsis][ellipsis]:
``` ```
$ ellipsis install user/id-mrjk $ ellipsis install direnv
``` ```
[ellipsis]: http://ellipsis.sh [ellipsis]: http://ellipsis.sh

View File

@ -1,18 +1,19 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# user/id-mrjk ellipsis package # direnv ellipsis package
ELLIPSIS_SHELL_BIN="$HOME/.local/bin" ELLIPSIS_SHELL_BIN="$HOME/.local/bin"
ELLIPSIS_SHELL_= ELLIPSIS_SHELL_HOME="$HOME/.local/shell"
detect_platform() { detect_platform() {
local kernel= machine= local kernel= machine=
kernel=$(uname -s | tr "[:upper:]" "[:lower:]") kernel=$(uname -s | tr "[:upper:]" "[:lower:]")
case "${kernel}" in case "${kernel}" in
mingw*) Darwin)
kernel=windows kernel=macOS
;; ;;
esac esac
case "$(uname -m)" in case "$(uname -m)" in
@ -38,42 +39,60 @@ detect_platform() {
get_github_release () { get_github_release () {
local repo=$1 local repo=$1
local pattern=$2 local pattern=$2
local version=${3:-latest} local version=${3-}
if [[ -n "${version:-}" ]]; then if [[ -n "${version:-}" ]] && [[ "$version" != 'latest' ]]; then
gh_url_suffix="tags/${version}" gh_url_suffix="tags/${version}"
else else
gh_url_suffix="latest" gh_url_suffix="latest"
fi fi
download_url=$( download_url=$(
curl -fL "https://api.github.com/repos/direnv/direnv/releases/$gh_url_suffix" \ curl -fL "https://api.github.com/repos/$repo/releases/$gh_url_suffix" \
| grep browser_download_url \ | grep browser_download_url \
| cut -d '"' -f 4 \ | cut -d '"' -f 4 \
| grep "$pattern" | 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: # The following hooks can be defined to customize behavior of your package:
pkg.install() { pkg.install() {
fs.link_files $PKG_PATH set -x
eval "$(detect_platform)" local bin=direnv
download_url=$(get_github_release direnv/direnv "direnv.$kernel.$machine" latest)
# 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"
#download_url=$(
# curl -fL "https://api.github.com/repos/direnv/direnv/releases/$gh_url_suffix" \
# | grep browser_download_url \
# | cut -d '"' -f 4 \
# | grep "direnv.$kernel.$machine"
#)
mkdir -p "$ELLIPSIS_SHELL_BIN"
curl -o "$ELLIPSIS_SHELL_BIN/direnv" -fL "$download_url"
chmod a+x "$ELLIPSIS_SHELL_BIN/direnv"
set +x 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() { # pkg.push() {