Archive

Posts Tagged ‘g’

The g Page

August 7th, 2009 subogero Comments off
G’s goal

“g” is a general-purpose command-line launcher for Gnome/Linux, an extended “gnome-open” which can open URLs, files or even programs in a new window. A bit like Windows “start”, just better.

“g” will open a new terminal window.

“g <CLI program>” will open it in a new fully independent terminal window.

“g <GTK+ program>” will open it in a fully independent window.

“g <URL>” will open it with the preferred application.

By an “independent window” I mean two things:

The starting terminal is not blocked while the started app is running;

Closing the starting terminal does not kill the started app.

Bonus: start a Google search for “foo bar” in your preferred browser with

g -g foo bar
Installation:

Download g.tar.gz and extract files in a new directory, preferably “g”.
Type “sudo make” for installation.
Enjoy.

Lessons learned:

How to decide if an argument of a shell-script is a program?

which $1
#prints the location of the command, or nothing if not a command

How to check if a shell-script has no arguments at all?

if [ $# -eq 0 ]

How to check if the last command returned no error in its exit status?

if [ $? -eq 0 ]

The trickiest: how to tell if a command is a terminal- or a GTK+ application?

Search for “libgtk-x11″ in it if it’s a compiled program.
Search for the respective gtk dependency if it’s an interpreter-script:

import gtk # Python
use Gtk2   # Perl

“g” knows these two at the moment, but the list should be extended to all known interpreted languages and graphical toolkits. Actually it should work the other way around, detecting terminal-only applications. But for instance Gimp contains the strings “stdin”, “stdout”, “stderr” and “printf” so I gave up.

I’ve created my first ever very officially looking manual page for “g”, credit goes to Jens Schweikhardt’s very helpful LINUX MAN PAGE HOWTO.

Tao in g

There is more Tao in “g” than in Windows “start”:

Try to start a native Windows program from command line which DOES NOT become fully detached, but blocks your command-line until it closes and returns an exit-status. Hmmm? On Linux, just omit “g”.

On Windows, the commands are scattered around in thousand folders, not listed in the PATH variable. On Linux, on the other hand, all commands are on the PATH, as there are only a few standard places to store them: /bin:/usr/bin:/usr/local/bin. So “g” can access them all.

View the manual page?

man g

Finally, how do you edit the “g” script itself?

g gedit g