1 |
=head1 GTK+ BASH FILE CHOOSER |
2 |
|
3 |
Gtk+ is a nice toolkit, but ever since the new file chooser was introduced |
4 |
in version 2, it became less and less usable. Not only is tab completion |
5 |
gone (at least in a useful form), quickly entering a path has become |
6 |
impossible due to many extra keys one has to press and due to the extreme |
7 |
slowness of the file chooser itself. |
8 |
|
9 |
As an example, when firefox finds a new filetype (e.g. a pdf) and I use |
10 |
its file chooser to select F</usr/bin/xpdf>, here is what happens: After |
11 |
typing F</usr/bin> the app freezes for around 40 seconds. Then it has |
12 |
loaded F</usr/bin> (this is on a typical debian install, F<ls -l /usr/bin> |
13 |
is much faster). Then after pressing return to select it, the window |
14 |
again freezes for about 30 seconds. In the gtk+ 1.0 file selector this |
15 |
took less than a second. As another example, when I save an image in |
16 |
the GIMP to F</tmp>, I can actually see the Gtk+ file chooser accessing |
17 |
other, automounted, paths such as F</fs/cdrom>, or F</fs/doom>, which |
18 |
are my dvd drive and an nfs fs on anoher machine. Mounting those takes |
19 |
additional time to the time required scanning F</tmp> (which again is |
20 |
about a minute). |
21 |
|
22 |
Clearly, this makes the Gtk+ file chooser completely |
23 |
unusable. Unfortunately, despite many people having opened bug reports |
24 |
about these problems, they are either getting ignored, or fixed in an |
25 |
half-assed attempt just to come back in the next gtk+ release. |
26 |
|
27 |
B<gtkbfc> is a hack that replaces the dreaded, slow and hard-to-use GTK+ |
28 |
file chooser by an rxvt-unicode window with a little script that lets you use |
29 |
readline tab-completion to enter filenames. |
30 |
|
31 |
Again, it's a dire hack and will not work with all programs. It does work |
32 |
for gimp, firefox, gedit at least, though. Most importantly, it does work |
33 |
for me, which really is all that counts. |
34 |
|
35 |
|
36 |
=head2 DEPENDENCIES |
37 |
|
38 |
The default helper requires F<rxvt-unicode> for terminal input. Other |
39 |
terminals won't do because they close all extra filehandles (and also do |
40 |
not support the less important --transient-for switch). As the helper is |
41 |
just a shell script you could rewrite it to use another mechanism to fetch |
42 |
the filename (such as a temporary file). Anything goes as long as the |
43 |
helper outputs an absolute pathname on stdout and exits. |
44 |
|
45 |
The default helper also requires F<bash>, as it has a F<read> built-in |
46 |
that is readline-enabled. Again, you can easily modify the helper script |
47 |
to use another hsell, or another mechanism. |
48 |
|
49 |
|
50 |
=head2 INSTALLATION |
51 |
|
52 |
Install rxvt-unicode. Then copy the F<gtkbfc-helper> to F</etc/> and make |
53 |
sure it's executable and opens a window where you can enter a filename when |
54 |
executed as F</etc/gtkbfc-helper>, which will then be echod to stdout. |
55 |
|
56 |
Then run F<make>, this will create a F<gtkbfc.so> shared object. You |
57 |
have to specify this shared object as LD_PRELOAD when running gtk |
58 |
programs. Either manually: |
59 |
|
60 |
LD_PRELOAD=/path/to/gtkbfc.so gimp |
61 |
|
62 |
Via an alias: |
63 |
|
64 |
alias gimp='LD_PRELOAD=/path/to/gtkbfc.so gimp' |
65 |
|
66 |
Or by putting it into your F</etc/ld.so.preload> (not really recommended |
67 |
for performance reasons). |
68 |
|
69 |
|
70 |
=head2 HOW DOES IT WORK |
71 |
|
72 |
B<gtkbfc> works by overriding the constructor for the GtkFileChooserWidget |
73 |
which is used in most file chooser applications. That is actually the |
74 |
clean part. The unclean part simply replaces some of the file chooser |
75 |
methods by methods that either do nothing or return the filename from the |
76 |
last invocation of the gtkbfc helper program. |
77 |
|
78 |
The original file chooser is kept in the background but is disabled, and |
79 |
is generally nonfunctional. To avoid minutes of file system scanning, |
80 |
B<gtkbfc> redirects the gtk+ file chooser to an empty file in an otherwise |
81 |
empty directory in F</tmp>. |
82 |
|
83 |
|
84 |
=head2 BUGS |
85 |
|
86 |
You want to use readline, so you are some kind of guru anyways, so if you |
87 |
have a bug report, better attach a patch or a very thorough analysis of |
88 |
what goes wrong to your e-mail. Thank you very much. |
89 |
|
90 |
|
91 |
=head2 AUTHOR |
92 |
|
93 |
Marc Lehmann <gtkbfc@schmorp.de>. |