Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute script after cd in a folder #1031

Open
Mte90 opened this issue Apr 1, 2025 · 3 comments
Open

Execute script after cd in a folder #1031

Mte90 opened this issue Apr 1, 2025 · 3 comments

Comments

@Mte90
Copy link

Mte90 commented Apr 1, 2025

As example I have this bash function:

# https://gist.github.com/kishannareshpal/342efc4a15e47ea5d338784d3e9a8d98
function activatevenv() {
  VIRTUALENV_DIRS=("venv/" "env/" ".env/" ".venv/" "${PWD##*/}")

  for dir in "${VIRTUALENV_DIRS[@]}"; do
    if [[ -d "${dir}" ]]; then
      if [[ -e "./${dir}/bin/activate" ]]; then
        source ./$dir/bin/activate
        break
      fi
    fi
  done

}
activatevenv

function cd() {
  builtin cd $1
  activatevenv
}

That I use with cd manually but I would like to do the same for zoxide.
Right now I use z folder and the cd command is not executed.

@brayner05
Copy link

I might be misunderstanding the issue, but could you not just create an alias?

@Mte90
Copy link
Author

Mte90 commented Apr 11, 2025

This:

function z() {
  z $1
  activatevenv
}

Doesn't work :-/

@brayner05
Copy link

Considering you're using Bash, see if this works:

function zoxide_custom() {
    command z "$1"
    activatevenv
}

alias z="zoxide_custom"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants