Every once in a while I have to fire up a GUI program from my terminal session to do something. It usually is Chrome to display some HTML file are some task alike.
These programs however throw warnings all over the place and it can actually become ridiculous to write anything so I always wanted to redirect stderr/stdout to /dev/null.
While ($PROGRAM &) &>/dev/null seems okay I decided to create a simple Bash function for it so I don’t have to repeat myself everytime.
So for now my solution is something like this:
#
# silly little function
#
gui ()
{
if [ $# -gt 0 ] ; then
($@ &) &>/dev/null
else
echo "missing argument"
fi
}
#
# silly little example
#
alias google-chrome='gui google-chrome'
So what I’m wondering about is:
- Is there a way without an endless list of aliases that’s still snappy?
- Are there different strategies to accomplish this?
- Do other shells offer different solutions?
In asking these questions I want to point out that your strategies and solutions might deviate substantially form mine. Redirecting output to /dev/null and aliasing it was the only way I know but there might be entirely different ways that are more efficient.
Hence this question 🙂
As others have pointed in the comments, I think the real problem is a way to distinguish between gui vs. non-gui apps on the commandline. As such, the cleanest way I could think of is to put this part of your script:
into a file called
gui, thenchmod +xit and put it in your~/bin/(make sure~/binis in your$PATH). Now you can launch gui apps with:on the prompt.
Alternatively, you can do the above, then make use of
bind:This will allow you to just do:
on the prompt and it would automatically append
guibeforegoogle-chromeOr, you can bind the above action to
F12instead ofRETURNwithTo separate what you want launched with
guivs. non-gui.More discussion on binding here and here.
These alternatives offer you a way out of endless aliases; a mix of:
guiin your~/bin/, andguitoF12as shown aboveseems the most ideal (albeit hacky) solution.
Update – @Enno Weichert’s Resultant Solution:
Rounding this solution out …
This would take care of aliases (in a somewhat whacky way though) and different escape encodings (in a more pragmatic rather than exhaustive way).
Put this in
$(HOME)/bin/quietAnd this in
$(HOME)/.inputrc