#!/usr/bin/env bash die() { printf "\n[tmux-fuzzy] %s\n" "$1" >&2 # keep popup visible if we're in a popup if [ -n "${TMUX:-}" ]; then printf "Press ENTER to close..." read -r _ || true fi exit 1 } list_tmuxinator_projects() { tmuxinator list 2>/dev/null \ | sed '1{/tmuxinator projects:/d;}' \ | tr -s '[:space:]' '\n' \ | grep -E '^[[:alnum:]_.:-]+$' \ || true } list_developer_dirs() { find ~/Developer -mindepth 1 -maxdepth 1 -type d -exec basename {} \; 2>/dev/null \ || true } list_projects() { { list_tmuxinator_projects list_developer_dirs } } # unique + sorted items="$(list_projects | sort -u)" [ -n "$items" ] || die "No projects found." sel="$( printf '%s\n' "$items" | fzf \ --prompt='Project > ' \ --height=100% --layout=reverse \ --print-query --expect=enter \ --bind 'tab:down,btab:up' \ --cycle )" || exit 0 key="$(printf '%s\n' "$sel" | sed -n '1p')" query="$(printf '%s\n' "$sel" | sed -n '2p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" choice="$(printf '%s\n' "$sel" | sed -n '3p')" project="${choice:-$query}" [ -n "$project" ] || exit 0 # Check if it's a tmuxinator project tmuxinator_projects="$(list_tmuxinator_projects)" is_tmuxinator=false if echo "$tmuxinator_projects" | grep -qxF "$project"; then is_tmuxinator=true fi # Check if it's a ~/Developer directory developer_dir="$HOME/Developer/$project" is_developer_dir=false if [ -d "$developer_dir" ]; then is_developer_dir=true fi if [ "$is_tmuxinator" = true ]; then tmuxinator start "$project" elif [ "$is_developer_dir" = true ]; then # Handle ~/Developer directory - create tmuxinator config if needed session_name="$project" tmuxinator_config="$HOME/.config/tmuxinator/${session_name}.yml" if [ ! -f "$tmuxinator_config" ]; then cp ~/.config/tmuxinator/template.yml.temp "$tmuxinator_config" sed -i '' "s|{{\$PROJECT_NAME}}|$session_name|g" "$tmuxinator_config" sed -i '' "s|{{\$PROJECT_ROOT}}|$developer_dir|g" "$tmuxinator_config" fi tmuxinator start "$session_name" else die "Project '$project' not found in tmuxinator or ~/Developer" fi exit 0