From 274c1491a38dcd34248c0b662b3526b0981d52b0 Mon Sep 17 00:00:00 2001 From: red Date: Sat, 17 May 2025 09:15:33 -0700 Subject: [PATCH] feat: exclude all active tmux session paths from fzf list --- tmux-sessionizer | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tmux-sessionizer b/tmux-sessionizer index ab3684f..c5608ba 100755 --- a/tmux-sessionizer +++ b/tmux-sessionizer @@ -68,13 +68,21 @@ fi # utility function to find directories find_dirs() { # list TMUX sessions + current_session="" + current_path="" + all_session_paths=() + if [[ -n "${TMUX}" ]]; then current_session=$(tmux display-message -p '#S') - tmux list-sessions -F "[TMUX] #{session_name}" 2>/dev/null | grep -vFx "[TMUX] $current_session" - else - tmux list-sessions -F "[TMUX] #{session_name}" 2>/dev/null + current_path=$(tmux display-message -p -t "$current_session" '#{session_path}') fi + while IFS= read -r path; do + all_session_paths+=("$path") + done < <(tmux list-sessions -F '#{session_path}' 2>/dev/null) + + tmux list-sessions -F "[TMUX] #{session_name}" 2>/dev/null | grep -vFx "[TMUX] $current_session" + # note: TS_SEARCH_PATHS is an array of paths to search for directories # if the path ends with :number, it will search for directories with a max depth of number ;) # if there is no number, it will search for directories with a max depth defined by TS_MAX_DEPTH or 1 if not set @@ -87,7 +95,10 @@ find_dirs() { path="$entry" fi - [[ -d "$path" ]] && find "$path" -mindepth 1 -maxdepth "${depth:-${TS_MAX_DEPTH:-1}}" -path '*/.git' -prune -o -type d -print + if [[ -d "$path" ]]; then + find "$path" -mindepth 1 -maxdepth "${depth:-${TS_MAX_DEPTH:-1}}" \ + -path '*/.git' -prune -o -type d -print | grep -vFx -f <(printf "%s\n" "${all_session_paths[@]}") + fi done }