From a7ed17f7de8c37fed9b2d5ee80d5483194a79cd4 Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 4 Aug 2022 19:10:12 +0200 Subject: Only display URL aliases instead of full URL --- url.sh | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/url.sh b/url.sh index c947ac4..985a2d2 100755 --- a/url.sh +++ b/url.sh @@ -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}" -- cgit v1.2.3-70-g09d2