Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter Behavior of xdg-open

I use the command xdg-open quite a lot in my Ubuntu Linux terminal. However, two things irk me:

  1. Is it possible to suppress the error messages?

  2. Is it possible to get the command to always complete? (That is, not continue running, so that I have another "new line" in my terminal).

I realize 2 may not be possible, because of the way the program works, but I imagine 1 is.

like image 706
pyrrhic Avatar asked Jan 13 '14 05:01

pyrrhic


2 Answers

First one is easy. Just

alias xdg-open="xdg-open 2>/dev/null"

If you want it permanently, just add that line to ~/.bashrc file.

I recommend you to think twice if you want to become blind to errors, though.

The second one is quite confusing to me. xdg-open shouldn't be intereactive. In my computer (Debian sid) xdg-open execs the command and ends, even if the command itself has not ended (ie: you have not closed the application opened for the URL). I think this should be the behaviour of xdg-open on any platform (it's supposed to work exactly the same way on any XDG system, that's its very purpose).

Anyway, for any command you launch in a shell, if you want it to be non-interactive, that is, to allow to enter commands even if the previous one hasn't finished, you just attach "&" to the end of it. Example:

# prompt is not shown until you close the calculator
$ gnome-calculator
# prompt is shown right after opening calculator and you can 
# work on the shell even if you don't close it
$ gnome-calculator &
like image 196
Flamma Avatar answered Oct 10 '22 06:10

Flamma


I maybe late for the answer, but I got exactly the same problem like you have / had.

I tried to start a URL with xdg-open, my default browser is firefox, and not xdg-open but firefox started with an error:

[user@user-pc ~]$ xdg-open https://www.google.de # the page opens fine, but firefox had an error
[user@user-pc ~]$ 
(process:3783): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed

# needed to press enter here

xdg-open closed fine but the firefox error stayed and I need to press enter to get the bash moving.


To get along this problem I called xdg-open within a new shell putting those output to /dev/null:

bash -c "xdg-open https://www.google.de" 2> /dev/null

The page opened fine, no error shown – rather nothing has been shown. And no need to press enter.

like image 32
Denny Avatar answered Oct 10 '22 05:10

Denny