Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add support for aliases to `ov` (#4409)

sarayourfriendc4cb14e7fd10
diff --git a/.gitignore b/.gitignore
index d443801df..e69e4c03a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,7 +13,7 @@ logs/
# Environment
.env
-.ovprofile
+.ov_aliases.json
# Python environments
env/
diff --git a/docker/dev_env/entrypoint.sh b/docker/dev_env/entrypoint.sh
index 53305cfbe..d8156b570 100755
--- a/docker/dev_env/entrypoint.sh
+++ b/docker/dev_env/entrypoint.sh
@@ -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"
diff --git a/docker/dev_env/expand_aliases.py b/docker/dev_env/expand_aliases.py
new file mode 100644
index 000000000..7d244f16e
--- /dev/null
+++ b/docker/dev_env/expand_aliases.py
@@ -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:])
diff --git a/justfile b/justfile
index 45c6dd140..0381c3be8 100644
--- a/justfile
+++ b/justfile
@@ -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
diff --git a/ov b/ov
index f260fee47..368ab831b 100755
--- a/ov
+++ b/ov
@@ -57,7 +57,7 @@ fi
case "$_cmd" in
init)
"$_self" build
- "$_self" just install-hooks
+ "$_self" 'just install-hooks && just init-ov-aliases'
;;
build)