update direnv config
This commit is contained in:
@@ -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
|
||||
|
||||
16
direnv/.config/direnv/lib/export-secret.sh
Normal file
16
direnv/.config/direnv/lib/export-secret.sh
Normal file
@@ -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}"
|
||||
}
|
||||
73
direnv/.config/direnv/lib/repo-overlay.sh
Normal file
73
direnv/.config/direnv/lib/repo-overlay.sh
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# repo_overlay - a direnv function to copy files from centralized overlays directory
|
||||
#
|
||||
# Set REPO_OVERLAY_DIR to customize the overlays base directory (default: $HOME/overlays)
|
||||
#
|
||||
# Usage: Add 'repo_overlay' to your .envrc file
|
||||
|
||||
repo-overlay() {
|
||||
# Get the repo URL from git remote
|
||||
local repo_url
|
||||
repo_url=$(git config --get remote.origin.url 2>/dev/null)
|
||||
|
||||
if [ -z "$repo_url" ]; then
|
||||
echo "repo_overlay: Not a git repository or no origin remote configured"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Extract owner and repo name from URL
|
||||
# Handles both SSH (git@github.com:owner/repo.git) and HTTPS (https://github.com/owner/repo.git)
|
||||
local owner_repo
|
||||
if [[ "$repo_url" =~ ^git@[^:]+:(.+)\.git$ ]] || \
|
||||
[[ "$repo_url" =~ ^https?://[^/]+/(.+)\.git$ ]] || \
|
||||
[[ "$repo_url" =~ ^git@[^:]+:(.+)$ ]] || \
|
||||
[[ "$repo_url" =~ ^https?://[^/]+/(.+)$ ]]; then
|
||||
owner_repo="${BASH_REMATCH[1]}"
|
||||
else
|
||||
echo "repo_overlay: Could not parse repository URL: $repo_url"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Determine overlay source directory
|
||||
local overlay_base="${REPO_OVERLAY_DIR:-$HOME/overlays}"
|
||||
local overlay_source="${overlay_base}/${owner_repo}"
|
||||
|
||||
if [ ! -d "$overlay_source" ]; then
|
||||
echo "repo_overlay: No overlay directory found at ${overlay_source}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Copy files from overlay directory
|
||||
local copied_count=0
|
||||
local skipped_count=0
|
||||
|
||||
# Find all files in overlay directory (excluding directories)
|
||||
while IFS= read -r -d '' source_file; do
|
||||
# Get relative path from overlay source
|
||||
local rel_path="${source_file#$overlay_source/}"
|
||||
local dest_file="./${rel_path}"
|
||||
|
||||
if [ -f "$dest_file" ]; then
|
||||
echo "repo_overlay: Skipping ${rel_path} (already exists)"
|
||||
((skipped_count++))
|
||||
else
|
||||
# Create parent directory if needed
|
||||
local dest_dir
|
||||
dest_dir=$(dirname "$dest_file")
|
||||
mkdir -p "$dest_dir"
|
||||
|
||||
# Copy the file
|
||||
cp "$source_file" "$dest_file"
|
||||
echo "repo_overlay: Copied ${rel_path}"
|
||||
((copied_count++))
|
||||
fi
|
||||
done < <(find "$overlay_source" -type f -print0)
|
||||
|
||||
# Summary
|
||||
if [ $copied_count -eq 0 ] && [ $skipped_count -eq 0 ]; then
|
||||
echo "repo_overlay: No files found in ${overlay_source}"
|
||||
else
|
||||
echo "repo_overlay: Complete (${copied_count} copied, ${skipped_count} skipped)"
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user