Keep track of file name completions with Viewglob

52

Author: Ben Martin

The Viewglob command-line utility lets you see the files available for your shell command completions in a separate window, leaving your regular terminal window uncluttered.

Viewglob packages are available for various versions of SUSE as well as Ubuntu Gutsy Gibbon. The main Viewglob download page also lists RPM packages for Fedora and Debian. The RPM packages for Fedora are for older versions of the distribution and are older versions of Viewglob itself, so I built from source using version 2.0.4. You can install Viewglob from source with the usual ./configure; make; sudo make install dance.

To start Viewglob, type viewglob. That starts a subshell attached to the current terminal in a window to the left of the normal shell prompt. The figure here shows completions for some files in /tmp. I pressed Tab twice to show the normal bash completion offering.

Viewglob doesn’t require any prompts from the user. Typing in cd v, for example, causes Viewglob to highlight any files in the current directory that start with “v.” Viewglob continues to narrow down the selected files as you type.

Things get a little more complicated if you want to branch out and use Viewglob from multiple tabs in a single terminal window, or from many terminal windows at once. The setup instructions in the FAQ for starting Viewglob from multiple sessions didn’t work for me as expected. When I started Viewglob from a new tab in gnome-terminal, only the tab that first started Viewglob showed completions. Similarly, when I started a new gnome-terminal window and started Viewglob, only the tab in the gnome-terminal window that first started Viewglob had any effect on the Viewglob window. This was also the case when I ran Viewglob from multiple instances of xterm.

To tell Viewglob to monitor and show completion results for the terminal you’re currently typing in, press Ctrl-G and Tab. If you want to send Ctrl-G to the terminal itself, then you must type it twice. Press Ctrl-G and then Ctrl-Space to toggle Viewglob on or off; this can be handy if you’re entering an extremely large directory and wish to temporarily avoid automatically completing offerings.

Remotely possible

Attempting to use Viewglob on a machine you have logged into over SSH can be a little tricky. I tried to SSH into ben@remotehost and run Viewglob with the --host=withXdisplay argument, where remotehost is a host that I can SSH into, and withXdisplay is the original host that I was using Viewglob on and which already had a Viewglob window running. This seemed to work at first, but upon closer inspection, the paths were being taken from the remote host, and the completions were being performed using the filesystem on the host withXdisplay. I discovered that this was caused by the way I set up the connection; I first started a gnome-terminal on withXdisplay and ran Viewglob for testing, then SSHed to ben@remotehost and ran Viewglob on the remote host, telling it to communicate with the graphical display using the --host=withXdisplay option to Viewglob. If, instead, I did not start Viewglob on the local host before SSHing to ben@remotehost, then the remote Viewglob session worked as expected.

The viewglob command is actually a script that calls other programs distributed with the Viewglob package to do the work. vgmini handles the display, vgd is the daemon that keeps things together, and vgseer handles the shell interaction. If you’re SSHing regularly into a host to use Viewglob, you might want to set up the configuration file ~/.viewglob/vgseer.conf on the remote host, and specify your default options and the host name where the display lives. The following configuration file turns off the yellow star icon displayed at the left of the prompt and sets a default host name for the display to live on:

shell-star off host withXdisplay

Viewglob communicates with the Viewglob daemon by default over port 16108. This is not encrypted, so if you’re SSHing into a remote host, you might want to redirect Viewglob to use --host=localhost and set up port forwarding using SSH to keep your file name information protected. You’re already starting an SSH session, so you might as well add in the port forwarding at the same time. You can protect Viewglob by adding a reverse port forwarding specification to the SSH command, and after you connect to the remote host, tell Viewglob to connect to the given port on localhost:

ben@withXDisplay$ ssh -R 16108:localhost:16108 ben@remotehost ben@remotehost$ viewglob --port=16108

One downside of the current version of Viewglob is that you can’t use it with GNU Screen. Also, when typing in more advanced shell command lines, sometimes Viewglob can get confused and give up providing path completions. This doesn’t effect the execution of the command, and Viewglob will start working again after you execute the current command line. However, Viewglob is effective at tracking the simpler command lines that one normally executes.

Viewglob doesn’t always try completions. For example, it doesn’t track subshells, it doesn’t attempt completion in the second or later parts of compound commands, and it ignores command substitution (execution of something inside backticks). For a full list, see the Notes section in Viewglob’s man page.

The main issue I had with Viewglob was remembering to press Ctrl-G and Tab to activate it whenever I changed terminals. It would be nice to have the option to switch the active terminal automatically whenever you start typing at a terminal that isn’t currently the active Viewglob terminal.

With Viewglob you can see filename completions without cluttering up the terminal itself. Viewglob can also operate over SSH to offer completions for remote terminals. Because path completions are always automatically offered by Viewglob, you will always know how many completions are available for a filename prefix and when you can use a single tab to uniquely complete the current filename prefix.

Categories:

  • Tools & Utilities
  • Desktop Software