XFile FAQ/Guide

File Types

XFile's file type associations are meant to be defined by the user. XFile distribution contains some generic file type definitions, which are installed in prefix†/share/XFile/types/system.db. Files in this directory, as well as $HOME/.xfile/types are sourced in alphabetical order, overriding identically named types defined earlier. Definitions under $HOME/.xfile/types have precedence over system wide definitions.

Basic Example

# A type definition starts with a descriptive type name
GIMP Image
{
	# Icon to be displayed for the file type
	# (name of an icon pixmap file†† without suffix)
	icon xcf
	
	# File name pattern
	match_name *.xcf
	
	# Action to be shown in file context menu (& designates the mnemonic character)
	# and command to be run. %n expands to the file name selected
	action &Open: gimp %n
}

prefix is platform dependent and is specified in the platform specific makefile.
†† The file must be located in prefix/share/xfile/icons or $HOME/.xfile/icons.

NOTE: Sourced database files as well as types defined within can be viewed by choosing the Help->File Types menu command.

Multiple patterns and actions may be specified, in groups as well:

match_name
{
	*.foo
	*.bar
	*.b?z
}

action
{
	View: foo %n
	Edit: bar %n
	Print: lpr %n
}

Matching File Contents

Files may also be identified by their contents by specifying offset (in bytes) into the file, followed by data to match. For example:

match_content 1 PDF

Will match the ASCII string "PDF" starting at byte 1 in the file.

Binary data may be specified as 8 bit hexadecimal values prefixed by the \ character. e.g. matching the ELF magic:

match_content 0 \7F\45\4C\46

Here as well, multiple patterns may be grouped as described earlier.

Type Database Variables

Using variables instead of actual command names in action fields makes it easy to control which application is used to open certain kinds of files by setting X resources, instead of modifying the file type database.

Variables for common applications may be defined using X resources: XFile.variables.name: value.

For example, following defines a variable named imageEditor and sets its value to gimp in Xresources/app-defaults:

XFile.variables.imageEditor: gimp

...which can then be specified in the type database as follows:

action Open: %imageEditor %n

XFile's default file type database makes use of several variables listed below. These should be set in Xresources according to user's preferences, since default values are arbitrary.

Variable Notes
terminal Terminal emulator. The command must treat all arguments passed to it as a list of commands and their respective arguments to be executed. The default value is xterm -e.
terminalHold Same as terminal above, but it should not quit after the execution finishes. The default value is xterm -hold -e.
textEditor Used for anything identified as text. Default value is xedit.
imageViewer, imageEditor Programs for viewing and editing images. View and Edit context menu items are shown for image files. Default values are ximaging and xpaint.
webBrowser HTML and other related file types are passed to this application. Default value is links -g.
audioPlayer, videoPlayer Default value for both is mplayer.
pdfViewerDefault is xpdf.

The Tools Menu

Custom tools may be added to XFile's Tools drop-down menu using X resources like this:

XFile.tools.name: command [arguments]

Arguments may contain context dependent variables:

† If more than one file is selected, the specified command will be run for each file separately.

Example

Adds a tool named search that runs the find command in xterm after prompting the user for search pattern:

XFile.tools.search: xterm -hold -e find %p -name %u

The menu button widget inherits tool's name, hence (if desired) its XmPushButton resources may be set as follows:

XFile*toolsMenu.search.labelString: Search...
XFile*toolsMenu.search.mnemonic: S
XFile*toolsMenu.search.acceleratorText: F3
XFile*toolsMenu.search.accelerator: <Key>F3

Opening Files Externally

If xfile binary is invoked as xfile-open <file name> ... through a symlink, which is normally installed along with the xfile binary, it will match given files against the type database and pass them to respective handlers, without launching XFile GUI (unless a name specified is a directory).

Some applications rely on Freedesktop's (shared-mime-info) file type association mechanism, and wont let the user specify a handler directly. Creating xfile-open.desktop file with roughly following contents:

[Desktop Entry]
Type=Application
Name=XFile/Open
NoDisplay=true
Exec=xfile-open %f
Icon=xfile_48x48
Terminal=false
MimeType=foo/bar;

...and placing it in /usr/share/applications or ~/.local/share/applications or /usr/local/share/applications or whatever, should add xfile-open to XDG handlers list in applications that present one (e.g. Firefox's download/helper applications prompt).

Additionally there is xdg-open from the xdg-utils package, which is also used to determine handlers, but apparently not by many.

Icons

XFile uses icons in XPM (X pixmap) format. Default icon set is installed in prefix/share/xfile/icons. The naming convention is: name.size.xpm while size may be either t, s, m, l (tiny, small medium and large, being 16, 24, 32 and 48 pixels† in size respectively). Custom icons may be installed in $HOME/.xfile/icons, and have precedence over those installed under prefix††

The size of icons displayed in the file list is chosen depending on the font height used for file name labels by default. This can be controlled with the XFile*iconSize: auto|tiny|small|medium|large resource.

t, s, m, l mnemonics are not really bound to any particular size in pixels, sizes listed above correspond to the default pixmap set.
†† prefix is platform dependent and is specified in the platform specific makefile.

Mount Points

XFile will highlight mount points (folder icon with green tab, bright green if mounted). The userMounts X resource specifies whether Un/Mount commands will be shown in the context menu for mount points. Additionally, mountCommand and unmountCommand resources may be set to override default mount commands.

NOTE: the host system must be configured accordingly to allow user mounts. See fstab(5) (fs_mntops) on Linuxen and vfs.usermounts for FreeBSD.

Mount Daemon

Additionally, XFile may be configured to utilize a mount daemon that manages a media directory, which is set using the mediaDirectory resource. If mediaDirectory is set, mediaMountCommand, mediaUnmountCommand must also be specified.

Here is an example Xresources configuration for udevil/devmon on Linux:

XFile.mediaDirectory: /media/$LOGNAME
XFile.mediaUnmountCommand: udevil umount
XFile.mediaMountCommand: udevil mount

Long File Names

XFile can abbreviate long file names for tighter column spacing. This feature is disabled by default and can be controlled with the XFile*fileList.shortenLabels resource by specifying the maximum number of characters to be displayed (the minimum is 12). Full file name will still be displayed in the status bar.


Back to XFile Homepage About