From 579bfd4048ea1298cda8b5228f5701c730f3538b Mon Sep 17 00:00:00 2001 From: jez Date: Tue, 18 Apr 2023 18:15:51 -0400 Subject: [PATCH] add: direnv config --- .gitignore | 1 + README.md | 4 ++-- ellipsis.sh | 67 ++++++++++++++++++++++++++++++++++------------------- 3 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f255f9a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +direnv diff --git a/README.md b/README.md index 4a2ebb6..3a6dbfa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/ellipsis.sh b/ellipsis.sh index 75822f9..f31fc9e 100644 --- a/ellipsis.sh +++ b/ellipsis.sh @@ -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 - gh_url_suffix="tags/${version}" - else - gh_url_suffix="latest" - fi + 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 - eval "$(detect_platform)" - download_url=$(get_github_release direnv/direnv "direnv.$kernel.$machine" latest) + 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" - #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() {