Skip to content

Instantly share code, notes, and snippets.

@a0s
Last active May 9, 2025 21:42
Show Gist options
  • Save a0s/7e16069a5991d7fff4f2d29d81e112d1 to your computer and use it in GitHub Desktop.
Save a0s/7e16069a5991d7fff4f2d29d81e112d1 to your computer and use it in GitHub Desktop.
Direnv: universal export_alias function
export_alias() {
local name=$1
shift
local alias_dir="$PWD/.direnv/aliases"
local alias_file="$alias_dir/$name"
local oldpath="$PATH"
mkdir -p "$alias_dir"
if ! [[ ":$PATH:" == *":$alias_dir:"* ]]; then
PATH_add "$alias_dir"
fi
{
echo '#!/usr/bin/env bash'
echo 'set -e'
echo "PATH=\"$oldpath\""
echo -n 'exec '
printf '%q ' "$@"
echo '"$@"'
} > "$alias_file"
chmod +x "$alias_file"
}
export_alias alembic-hrev bash -c 'alembic revision --rev-id "$(date +%Y_%m_%d_%H%M)" -m "$*"' _
# Usage: alembic-hrev "initial migration"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment