From 8441ef33a2c2b40daa2dd5fa48e7ade516798642 Mon Sep 17 00:00:00 2001 From: Guilherme Zagatti Date: Thu, 5 Dec 2024 15:07:03 +0100 Subject: [PATCH] add uv configuration --- direnv/direnvrc | 11 +++++++++++ shells/zshrc | 29 ++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/direnv/direnvrc b/direnv/direnvrc index 322f0cd..fb62360 100644 --- a/direnv/direnvrc +++ b/direnv/direnvrc @@ -11,3 +11,14 @@ layout_pyenv() { fi fi } + +layout_uv() { + if [[ -d ".venv" ]]; then + local VIRTUAL_ENV="$(pwd)/.venv" + source "$VIRTUAL_ENV/bin/activate" + PATH_add "$VIRTUAL_ENV/bin" + export UV_ACTIVE=1 + else + echo -e "\e[38:5:1mUV virtual environment not available.\e[0m" + fi +} diff --git a/shells/zshrc b/shells/zshrc index f7fe852..e9893f2 100644 --- a/shells/zshrc +++ b/shells/zshrc @@ -305,10 +305,25 @@ if [[ $- == *i* ]]; then # information about the current dev environment _devenv_info() { if hash $1 2>/dev/null; then - local venv=$($1 version-name) - if [ -n "$venv" ] && [ $venv != system ]; then - printf "$2 $venv" - fi + case "$1" in + pyenv|rbenv) + local venv=$($1 version-name) + if [ -n "$venv" ] && [ $venv != system ]; then + printf "$2 $venv" + fi + ;; + uv) + if [ -n "$VIRTUAL_ENV" ] && [ -n "$VIRTUAL_ENV_PROMPT" ]; then + # local venv="${VIRTUAL_ENV_PROMPT#*(}" + local venv="${VIRTUAL_ENV_PROMPT%)*}" + venv="${venv#*\(}" + printf "py uv $venv" + fi + ;; + *) + exit 1 + ;; + esac fi return } @@ -340,9 +355,9 @@ if [[ $- == *i* ]]; then dev_info_msg="${dev_info_msg}nix-shell" fi - local pyenv_info_msg=`_devenv_info pyenv py` - if [[ -n $pyenv_info_msg ]]; then - dev_info_msg="${dev_info_msg}${pyenv_info_msg}" + local uv_info_msg=`_devenv_info uv` + if [[ -n $uv_info_msg ]]; then + dev_info_msg="${dev_info_msg}${uv_info_msg}" fi local rbenv_info_msg=`_devenv_info rbenv rb`