rupa / z

z - jump around
Do What The F*ck You Want To Public License
16.39k stars 1.17k forks source link

exclude all dirs under a path #189

Open dmd opened 8 years ago

dmd commented 8 years ago

_Z_EXCLUDE_DIRS appears to exclude a single path.

I'd like to exclude, say, all of /netmounts

rupa commented 7 years ago

I think its reasonable request to allow wildcards, happy to look at a patch or I'll get around to it whenever

kaaresl commented 4 years ago

Say we can have glob patterns in _Z_EXCLUDE_DIRS. One solution for zsh is to use the ${~var} variable format. This lets us have glob patterns and zsh will evaluate it before further execution.

I'm having trouble finding a solution for bash. The closest thing I've got is this:

            if [[ -n "$BASH_VERSION" ]]; then
                $(eval [[ "$*" == "$exclude" ]]) && return
            else

but this chokes for directories with spaces in them. The full version is:

        # don't track excluded directory trees
        local exclude
        for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do
            if [[ -n "$ZSH_VERSION" ]]; then
                [[ "$*" == ${~exclude} ]] && return
            elif [[ -n "$BASH_VERSION" ]]; then
                $(eval [[ "$*" == "$exclude" ]]) && return
            else
                case "$*" in "$exclude") return;; esac
            fi
        done

So not being able to exclude folders with space in the names is a show-stopper for me. This still needs to be adressed, or just say "zsh only".

kaaresl commented 4 years ago

See 5711b4efef45bc1cd9bbca92c5ce6c6981d919bb

kaaresl commented 4 years ago

This is actually a bug. I think the intention of the original code was to match all folders underneath each entry in _Z_EXCLUDE_DIRS with this test:

        # don't track excluded directory trees
        local exclude
        for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do
            case "$*" in "$exclude*") return;; esac
        done

The glob wildcard have to be outside the string, which will make this work like intended, and according to @dmd's request. Like so:

            case "$*" in "$exclude"*) return;; esac