Skip to content

Instantly share code, notes, and snippets.

@Efreak
Created June 28, 2022 04:50
Show Gist options
  • Save Efreak/d476e40c0db348edd626f78e0ae15009 to your computer and use it in GitHub Desktop.
Save Efreak/d476e40c0db348edd626f78e0ae15009 to your computer and use it in GitHub Desktop.
a script to edit a url inline using whiptail, then open it in a browser
# check what's available for opening the url.
# sensible-browser requires an environment variable :(
# see xdg-open spurce: https://github.com/freedesktop/xdg-utils
# todo: maybe use a second whiptail checklist to pick browser?
# todo: a chooser for termux-open options (send/view, chooser)
for app in $BROWSER termux-open xdg-open firefox elinks links2 links lynx w3m
do
if
type $app > /dev/null 2>&1
then
opener=$app
break
fi
done
URL=$(whiptail --inputbox "Edit your url here:" 8 70 "$1" \
--title "Edit: $1" 3>&1 1>&2 2>&3)
# The `3>&1 1>&2 2>&3` is a small trick to swap the stderr with stdout
# Now to check if the user pressed OK or Cancel
exitstatus=$?
echo Original URL: "$1" # in case the user wants to use it again
if [ $exitstatus = 0 ]; then
echo "New URL: $URL"
$opener "$URL"
else
echo "Cancelled."
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment