'Zenity: How To Get List Selection From Key/Value Associative Array?

How do I take the key/values from an associative array and display them in a Zenity list dialog?

Example:

#!/bin/bash

get_final_bookmarks_choice(){
    if [ ${#matched_bookmarks[@]} -eq 1 ]; then
        # open_bookmarks_command
        return
    fi
    # guard clause.  If no bm found.
    if [ -${#matched_bookmarks[@]} -eq 0 ]; then 
        msg='No bookmarks match found.'
        notify-send "$msg"; echo "$msg"
        return
    fi

    bm_url=$(zenity --entry --title="Multi matches found" \
    --text="Choose bookmark" \
    --column="Name" --column="URL" \

    # Key/value dictionary here.
    )
    # Return the key.
    echo "$key returned here."
}


declare -A matched_bookmarks
matched_bookmarks=(
    ['match 1']='http://match1.com'
    ['match 2']='http://match2.com'
    ['match 3']='http://match3.com'
)

bm_name="$(get_final_bookmarks_choice)"

bm_url="${matched_bookmarks[$bm_name]}"

echo "Bookmarks URL:$bm_url"


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source