Skip to content

Instantly share code, notes, and snippets.

@SuzanaK
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SuzanaK/2493a54678424b57f758 to your computer and use it in GitHub Desktop.
Save SuzanaK/2493a54678424b57f758 to your computer and use it in GitHub Desktop.
script to automatically google error messages printed to STDERR, using firefox
#! /bin/bash
usage="\nWill google the error message from COMMAND, using Firefox.
\nUsage: COMMAND |& $0 \n or COMMAND 2>&1 >/dev/null | $0 (to silence STDIN) \n or $0 ERROR_MESSAGE"
if [ "$*" ] ; then
input="$*"
else
read -t0.2 -d'' -r input
fi
# replace all whitespace with simple spaces
input=${input//[[:space:]]/ }
if [ -z "$input" ] ; then
echo -e $usage
exit 0
fi
wid=`xdotool search --onlyvisible --name "Mozilla Firefox" | head -1`
if [ "$wid" = "" ] ; then
exec firefox &
sleep 3s
fi
wid=`xdotool search --onlyvisible --name "Mozilla Firefox" | head -1`
actual=`xdotool getactivewindow`
if [ $wid != $actual ]; then
xdotool windowactivate $wid
fi
# google arguments
xdotool key ctrl+t
xdotool key ctrl+j
xdotool type "$input"
xdotool key Return
echo "Finished googling the following error message:"
echo -e $input
exit 0
@SuzanaK
Copy link
Author

SuzanaK commented May 27, 2015

Will use an existing firefox window to open a new tab or start a new firefox window, and search the error message in the default search engine. Requires xdotool.

@SuzanaK
Copy link
Author

SuzanaK commented May 27, 2015

Known Issue: xdotool won't type special characters like "Umlaute" (ä, ö, ü) that may be contained in the error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment