Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # menu.sh — universal fzf menu
- menu() {
- local -a options=("${@}")
- local formatted=()
- local i=1
- for option in "${options[@]}"; do
- formatted+=("$(printf "%02d) %s" "$i" "$option")")
- ((i++))
- done
- # Use fzf with --print-query and fallback logic
- local result query selection
- result=$(printf "%s\n" "${formatted[@]}" | fzf --prompt="Choose: " --height=40% --reverse --print-query)
- query=$(echo "$result" | sed -n '1p')
- selection=$(echo "$result" | sed -n '2p' | sed 's/^[0-9][0-9]*) //')
- # Return selection if not empty, otherwise the query
- printf "%s\n" "${selection:-$query}"
- }
Advertisement
Add Comment
Please, Sign In to add comment