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"
You have to use array, not associative array, as argument to
zenitycommand:Here is my version of your script:
For fun, a SE based version:
should produce something like: