#!/usr/bin/env zsh local dot_glob=$1 local only_dirs=$2 local dirs=("${@:3}") (( $#dirs )) || return 0 local -a bin local -a flags () { emulate -L zsh # Set dot_glob in case the value of find-flags depends on it (via `zstyle -e`). # Ideally we should run this with user options. (( dot_glob )) && setopt dot_glob local widget=${WIDGET#z4h-} zstyle -a :z4h:$widget find-command bin if (( ! $#bin )); then if (( $+commands[bfs] )); then bin=(command bfs) else bin=(command find) fi fi zstyle -a :z4h:$widget find-flags flags if (( ! $#flags )); then flags=(-name '.*' -prune -print -o -print) fi } local -a cmd local -aU fss fss=(${(f)"$("${bin[@]}" / . -maxdepth 0 -printf '%F\n' 2>/dev/null)"}) || fss=() if (( $#fss )) && [[ -z ${(M)fss:#unknown} ]]; then cmd+=("${bin[@]}" -L ./$^dirs) (( only_dirs )) && cmd+=('!' -type d -prune -o) cmd+=('!' '(') local fs for fs in $fss; do cmd+=(-fstype $fs -o) done cmd[-1]=(')' -prune '(' "${flags[@]}" ')') (( dot_glob )) || cmd+=(-o -name '.*' -prune) cmd+=(-o "${flags[@]}") else cmd+=("${bin[@]}" -L . -xdev -mindepth 1) (( only_dirs )) && cmd+=('!' -type d -prune -o) cmd+=('!' -path './*/*' '!' '(') local dir for dir in $dirs; do cmd+=(-name ${(b)dir} -o) done cmd[-1]=(')' -prune) (( dot_glob )) || cmd+=(-o -name '.*' -prune) cmd+=(-o "${flags[@]}") fi "${cmd[@]}"