diff options
Diffstat (limited to 'url.sh')
-rwxr-xr-x | url.sh | 35 |
1 files changed, 23 insertions, 12 deletions
@@ -36,21 +36,32 @@ then fi # let user select the URL -closer="close menu" -line="$(sed "$ a ${closer}" < "${data_abs}" | ${menu} -i -l 10)" -selection="$(echo "${line}" | awk -F '\t' '{print $1}')" +closer="[close menu]" +options="$(awk -F '\t' '{print $2}' < "${data_abs}" | sed "$ a ${closer}")" +key="$(echo "${options}" | ${menu} -i -l 10)" -# exit or open URL in browser -if [ "${selection}" = "${closer}" ] +# close if user selected the close entry or stopped menu with ESC +if [ "${key}" = "${closer}" ] || [ "${key}" = "" ] then exit 0 +fi -# exit if nothing is selected -elif [ "${selection}" = "" ] -then - exit 0 +# search for the selected key in data file +url="" +while read -r line +do + if [ "$(echo "${line}" | awk -F '\t' '{print $2}')" = "${key}" ] + then + if [ "${url}" = "" ] + then + url="$(echo "${line}" | awk -F '\t' '{print $1}')" + else + # warn if multiple URLs have this key + echo "More than one URL in data file matching selected key!" 1>&2 + break + fi + fi +done < "${data_abs}" # open selected URL in browser -else - firefox "${selection}" -fi +firefox "${url}" |