Sometimes when i am using certain applications (especially text editors), the applications themselves do not make URLs that are written out clickable and openable in my default browser. Usually, this would result in me having to highlight the link, copy it to the clipboard, switch to my web browser, open a new tab, paste the link and go.
However, the quick hack for Fedora described in this tutorial will set up a keyboard shortcut so you can simply highlight the link text, do a keyboard shortcut, and the link will open up in your default browser.
Step 1 — Download xsel
first up we need to download a little command line utility called xsel that will let us get at the clipboard selection from a bash script. Install xsel with the command:
sudo yum install xsel
Step 2 — create the script in your user’s bin directory
If you don’t already have it, create a directory called
in the .local directory in your home directory:
Then edit a new file in ~/.local/bin (i called mine openindefaultbrowser):
Now, add the following code to the openindefaultbrowser file, and save it.
#!/bin/bash xdg-open $(xsel -p)
Now, finally, make the script executable with the command:
chmod +x ~/.local/bin/openindefaultbrowser
Step 3 — bind your new script to a keyboard shortcut
Open up the keyboard preferences, and switch to the “shortcuts” tab. Click “Custom Shortcuts” from the list on the left, and then click the + button to add a new shortcut. Name the shortcut whatever you want and put the name of your script in the command field and press add.
Now, click on the shortcut, and assign an keyboard combo. (i chose super+F).
Ready to go
Your new shortcut should be ready to go. To use it, highlight (select) the text of a url, press your keyboard shortcut, and your webbrowser should open up with the link you highlighted. Note that this script is not smart, if you highlight something that is not a url, and press the shortcut, it will try to open it as it was a url 🙂
This is awesome!!!
The script should probably go into
~/.local/bin to make selinux happy.
Thanks Christoph! I have updated the post. 🙂
Wait. I miss the original location but whats the problem with ~/bin and selinux?
It will work with the targeted policy, but not with strict.
A slightly updated script to handle selections without http protocol (at least this is the case on my opensuse)
if [[ $LINK != http://* ]]
of course, another workaround to this would be just to use the command for your browser directly in the script, rather than the xdg-open one (that opens in the default app for whatever you pass it).
Hy, someone with this error?
xdg-open: unexpected argument '+x'
Try 'xdg-open --help' for more information.
xdg-open $(xsel -p)
This script works my using the currently highlighted text (aka the middle click clipboard) as the URL to pass to the browser. It seems that the last thing you highlighted before running the script was the line to change the permissions of the script (i think that is where the “+x” is coming from) if you highlight a URL, and run the script it should work as expected.