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.
## Install
Clone and symlink or install with [ellipsis][ellipsis]:
```
$ ellipsis install user/id-mrjk
$ ellipsis install direnv
```
[ellipsis]: http://ellipsis.sh

View File

@ -1,18 +1,19 @@
#!/usr/bin/env bash
#
# user/id-mrjk ellipsis package
# direnv ellipsis package
ELLIPSIS_SHELL_BIN="$HOME/.local/bin"
ELLIPSIS_SHELL_=
ELLIPSIS_SHELL_HOME="$HOME/.local/shell"
detect_platform() {
local kernel= machine=
kernel=$(uname -s | tr "[:upper:]" "[:lower:]")
case "${kernel}" in
mingw*)
kernel=windows
Darwin)
kernel=macOS
;;
esac
case "$(uname -m)" in
@ -38,42 +39,60 @@ detect_platform() {
get_github_release () {
local repo=$1
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}"
else
gh_url_suffix="latest"
fi
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 \
| 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() {
fs.link_files $PKG_PATH
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)
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
}
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() {