1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash

set -euo pipefail
if [[ "${TRACE-0}" == "1" ]]; then
    set -o xtrace
fi

main() {
    # Float via fzf's own tmux popup, unless the caller already gave us a
    # floating container (e.g. a tmux binding running this in a floating pane),
    # where --tmux would open a redundant popup on top.
    local tmux_opts=(--tmux "80%,60%")
    [[ -n "${IN_TMUX_FLOAT:-}" ]] && tmux_opts=()

    local dir
    # ${arr[@]+"${arr[@]}"} splices the array only when it has elements. A bare
    # "${tmux_opts[@]}" would abort under `set -u` on the empty (IN_TMUX_FLOAT)
    # path, because macOS bash 3.2 counts an empty array as an unbound variable.
    # --no-sort keeps zoxide's frecency order instead of letting fzf re-rank by
    # fuzzy match score, so the dirs you actually visit stay near the top.
    # --exact keeps loose matches out: with frecency ordering, they are just noise.
    dir=$(zoxide query --list "$@" | fzf --no-multi --select-1 --no-margin --no-padding \
        ${tmux_opts[@]+"${tmux_opts[@]}"} \
        --no-sort --exact \
        --height 100% \
        --highlight-line --info inline-right \
        --border-label ' zoxide ' \
        --preview 'eza --tree --level=2 --color=always {}' \
        --bind 'ctrl-/:change-preview-window(down|hidden|)') || exit 0

    local name
    name=$(basename "$dir")

    tmux new-window -n "$name" -c "$dir"
}

main "$@"