Last active
May 9, 2025 21:42
-
-
Save a0s/7e16069a5991d7fff4f2d29d81e112d1 to your computer and use it in GitHub Desktop.
Direnv: universal export_alias function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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