Skip to content

Commit

Permalink
Add support for aliases to ov (#4409)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend authored May 31, 2024
1 parent 1f24ba1 commit c4cb14e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ logs/

# Environment
.env
.ovprofile
.ov_aliases.json

# Python environments
env/
Expand Down
3 changes: 2 additions & 1 deletion docker/dev_env/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ if [ -n "$PDM_CACHE_DIR" ]; then
pdm config install.cache on
fi

bash -c "$*"
expanded_args=$(python3 "$OPENVERSE_PROJECT"/docker/dev_env/expand_aliases.py "$@")
bash -c "$expanded_args"
28 changes: 28 additions & 0 deletions docker/dev_env/expand_aliases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import json
import os
import sys
from pathlib import Path


SHARED_ALIASES = {
"j": ["just"],
"nuxt": ["j", "p", "frontend", "dev"],
}


def expand_aliases(args: list[str]):
ov_aliases = Path(os.getenv("OPENVERSE_PROJECT")) / ".ov_aliases.json"
aliases = SHARED_ALIASES
if ov_aliases.is_file():
aliases |= json.loads(ov_aliases.read_text())

args = sys.argv[1:]

while args[0] in aliases:
args = aliases.pop(args[0]) + args[1:]

print(*args)


if __name__ == "__main__":
expand_aliases(sys.argv[1:])
23 changes: 23 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ install:
@install-hooks:
bash -c "cp ./docker/dev_env/hooks/* ./.git/hooks"

# Create an `.ov_aliases.json` as a starting point for development environment customisation. Does not make changes if the file already exists.
init-ov-aliases:
#! /usr/bin/env bash
[[ -f ./.ov_aliases.json ]] && echo '.ov_aliases.json already exists! No changes made.' && exit 0 || cat <<-'EOALIASES' > ./.ov_aliases.json
{
"welcome": ["just", "welcome-to-openverse"]
}
EOALIASES

# Recipe used as example alias in default .ovprofile (see init-ovprofile)
welcome-to-openverse:
#! /usr/bin/env bash
# ASCII art courtesy of http://patorjk.com/software/taag/#p=display&f=Big&t=Openverse
cat <<OPENVERSE
___ ____ ___ ____ __ __ ___ ____ _____ ___
/ \ | \ / _]| \ | | | / _]| \ / ___/ / _]
| || o ) [_ | _ || | | / [_ | D )( \_ / [_
| O || _/ _]| | || | || _]| / \__ || _]
| || | | [_ | | || : || [_ | \ / \ || [_
| || | | || | | \ / | || . \ \ || |
\___/ |__| |_____||__|__| \_/ |_____||__|\_| \___||_____|
OPENVERSE

# Setup pre-commit as a Git hook
precommit:
#!/usr/bin/env bash
Expand Down
2 changes: 1 addition & 1 deletion ov
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fi
case "$_cmd" in
init)
"$_self" build
"$_self" just install-hooks
"$_self" 'just install-hooks && just init-ov-aliases'
;;

build)
Expand Down

0 comments on commit c4cb14e

Please sign in to comment.