I have a code that looks like this:
has_venv_in_path() {
    unsetopt nomatch 2>/dev/null
    local path_to_search
    path_to_search=$1
    echo "searching in $path_to_search"
    if [[ ${path_to_search} = "/" ]]; then
        echo "no"
    fi
    ls ${path_to_search}/*/bin/activate > /dev/null 2> /dev/null
    if [ "$?" = '0' ]; then
        echo "yes"
    else
        has_venv_in_path $(dirname "$path_to_search")
    fi
}
has_venv_in_path function is written by me and it works if the path provided to it doesn't contain tilde like /home/user/foo. If ~/foo is provided that is going into infinite recursion.
So I found how to expand tilde, but I have very little knowledge of bash, so I can't properly use it in my function.
Can anyone help with that?
Suppose we have following folder structure.
/code/foo/bar/baz
/code/foo/venv/bin/activate
- if we cdinto/code/foo/bar/baz, it should activate venv.
- if we cdinto/code/foo, it should activate venv
- if we cdout of/code/foo/*, it should deactivate venv.
 
     
     
    