From a23415c69a49e0515e00815b1045bcdac3b696e4 Mon Sep 17 00:00:00 2001 From: Jason Swank Date: Fri, 23 Jan 2026 18:23:08 +0000 Subject: [PATCH] update direnv setup --- README.md | 11 +++++------ ctx/home/.config/direnv/direnvrc | 19 ++++--------------- ctx/home/.config/direnv/lib/export-secret.sh | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 ctx/home/.config/direnv/lib/export-secret.sh diff --git a/README.md b/README.md index e2312ca..47c3bf2 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,8 @@ exit ## More Info -The image is based on *alpine:3*, with a small amount of additional -setup/installation done. See the [Dockerfile](Dockerfile) and [ctx/home](ctx) -for the specifics. +The image is based on *alpine:3* with a small amount of additional setup/installation. +See the [Dockerfile](Dockerfile) and [ctx/home](ctx) for the specifics. - Some basic utilities are installed for interative and script-based shell usage - A user is created with sudo (`-u root`) access. @@ -38,9 +37,9 @@ See ghcr.io/jswank/alpine-cli for current available images. ## Helper Script -A helper script, using [casey/just](https://github.com/casey/just') is in -[bin/cli](bin/cli). It can be used to quickly start an ephemeral (or -persistent) container. +[bin/cli](./bin/cli) is a helper script using +[casey/just](https://github.com/casey/just'). It can be used to quickly start an +ephemeral (or persistent) container. ```console $ bin/cli help diff --git a/ctx/home/.config/direnv/direnvrc b/ctx/home/.config/direnv/direnvrc index df319ab..0eff220 100644 --- a/ctx/home/.config/direnv/direnvrc +++ b/ctx/home/.config/direnv/direnvrc @@ -1,15 +1,4 @@ -export_secret() { - local name="$1" - local file="/run/secrets/${name}" - - if [[ ! -f "$file" ]]; then - printf "secret file not found: %s\n" $file >&2 - return 1 - fi - - # Read first line, remove trailing spaces/tabs, convert nulls to newlines - local value - value=$(head -n1 "$file" | sed 's/[ \t]*$//' | tr '\0' '\n') - - export "${name}=${value}" -} +# Source library files in alphabetical order +for lib in ~/.config/direnv/lib/*.sh; do + [[ -f "$lib" ]] && source "$lib" +done diff --git a/ctx/home/.config/direnv/lib/export-secret.sh b/ctx/home/.config/direnv/lib/export-secret.sh new file mode 100644 index 0000000..c958bea --- /dev/null +++ b/ctx/home/.config/direnv/lib/export-secret.sh @@ -0,0 +1,16 @@ +# Exports a Podman / Docker secret as an environment variable +export-secret() { + local name="$1" + local file="/run/secrets/${name}" + + if [[ ! -f "$file" ]]; then + printf "secret file not found: %s\n" $file >&2 + return 1 + fi + + # Read first line, remove trailing spaces/tabs, convert nulls to newlines + local value + value=$(head -n1 "$file" | sed 's/[ \t]*$//' | tr '\0' '\n') + + export "${name}=${value}" +}