English | 日本語
The File Extension Associations feature allows you to configure which programs XeFM uses to open, view, and edit different types of files based on their extensions. This provides a flexible way to customize how XeFM handles various file types.
File associations let you configure which programs XeFM uses to open, view, and edit different file types. For example, you can use Preview for viewing images but Photoshop for editing them.
Add this to your ~/.xefm/config.py:
FILE_ASSOCIATIONS = [
# Images: Multiple patterns, Preview for viewing, Photoshop for editing
{
'pattern': ['*.jpg', '*.jpeg', '*.png', '*.gif'],
'open|view': ['open', '-a', 'Preview'], # Same for open and view
'edit': ['open', '-a', 'Photoshop']
},
# Videos: QuickTime for viewing, Final Cut for editing
{
'pattern': ['*.mp4', '*.mov'],
'open|view': ['open', '-a', 'QuickTime Player'],
'edit': ['open', '-a', 'Final Cut Pro']
},
# PDFs: Preview for viewing, Acrobat for editing
{
'pattern': '*.pdf',
'open|view': ['open', '-a', 'Preview'],
'edit': ['open', '-a', 'Adobe Acrobat']
}
]
File associations are configured in your ~/.xefm/config.py file using the FILE_ASSOCIATIONS list.
FILE_ASSOCIATIONS = [
{
'pattern': '*.ext' or ['*.ext1', '*.ext2'], # Single or multiple
'open|view': ['command', 'args'], # Combined actions
'edit': ['command', 'args'] # Separate action
}
]
| to assign same command to multiple actionsEach file pattern can configure up to four actions:
| Action | Run by | What it does | Value |
|---|---|---|---|
| enter | open_item (Enter) |
Casual open — handled inside XeFM | A built-in handler name, or an XeFM action |
| open | open_with_os, open_items_with_os |
Deliberate open — hands off to another app | A command, or an XeFM action |
| view | view_file, view_files |
View the file | A command, or an XeFM action |
| edit | edit_file, edit_files |
Edit the file | A command, or an XeFM action |
Each of open, view and edit has two actions: one for the file under the
cursor (open_with_os, view_file, edit_file) and one for the
selection, or the file under the cursor when nothing is selected
(open_items_with_os, view_files, edit_files). Both read the same rule;
with several files, each goes where its own rule sends it.
Keys depend on your keymap preset — see Keymap Presets.
A rule can also carry an open_with list: the programs
Open With offers for its files. It is not an action —
every matching rule’s list is offered, not only the first one’s.
open_item and open_with_os are deliberately different gestures:
Enter never leaves XeFM. It enters directories, browses archives, and
opens files in the built-in viewer. It is safe to lean on — it will not
launch an application or steal focus.open_with_os hands the file to a real application. Use it when you
actually want Preview, an IDE, or the OS default app. In a desktop window it
answers a modifier on the same Enter that opens, as well as its usual key.Because the enter tier stays inside XeFM, its value names a built-in
handler rather than a program to launch:
| Value | Effect |
|---|---|
'viewer' |
Open in the built-in text/markdown viewer |
'navigate' |
Browse the file as an archive, whatever its name; XeFM tells the format from its contents |
'list' |
Open the file as a file list, one path per line (the default for *.m3u, *.m3u8) |
None |
Do nothing |
| (no rule) | XeFM’s default: enter directories and archives, view files |
{
'pattern': '*.csv',
'enter': 'viewer', # Enter -> built-in viewer
'open': ['open', '-a', 'Numbers'], # open_with_os -> Numbers
}
The enter value can also name an XeFM action. See the next section.
Any of the four can run an XeFM action instead: a named command of the
kind keys, menus and the command palette run. It can be one of XeFM’s own,
one from your ACTIONS, or one an extension adds.
Write it as {'action': '<name>'}, in every verb. The dict form leaves
room for more keys later, and keeps an action apart from a command line or a
handler name.
For example, with the os-preview extension installed, Enter on a video shows it in Quick Look instead of reporting that XeFM has no built-in viewer for it:
{
'pattern': ['*.mp4', '*.mov', '*.mp3', '*.m4a'],
'enter': {'action': 'preview.show'}, # Enter -> Quick Look
'open': ['open', '-a', 'QuickTime Player'],
},
{
'pattern': ['*.docx', '*.xlsx', '*.pptx'],
'view': {'action': 'preview.show'}, # view_file -> Quick Look
},
enter, open_with_os, view_file and edit_file that is the file
under the cursor, even when other files are selected. From
open_items_with_os, view_files and edit_files it is the selected files
whose rule names it; the others go where their own rules send them, as
with commands.enter, a command
line in open, view and edit. An action can share a program’s name
(rename), which is why it is always written as a dict.edit_file falls back to TEXT_EDITOR, and so on.FILE_ASSOCIATIONS themselves (open_item,
open_with_os, open_items_with_os, view_file, view_files,
edit_file, edit_files) cannot be named. They could end up running
each other round and round.Programs can be specified in two formats:
'open': ['open', '-a', 'Preview']
'open': 'open -a Preview'
'edit': None # No editor configured for this file type
For view, None means something more specific: use the built-in
viewer. See Text Files.
Unmarked, you do not declare this. Whether XeFM hands over the display is a property of the backend you are running, not of the program you configured:
| Mode | What happens when an unmarked program launches |
|---|---|
Terminal (--backend tui) |
XeFM suspends, the program owns the terminal, XeFM restores and repaints when it exits |
| Desktop mode | There is no terminal to hand over, so the program runs in the background and XeFM stays responsive |
So 'view': ['less'] simply works in terminal mode — no marking needed:
{
'pattern': '*.log',
'view': ['less'], # terminal mode hands the display over and waits
'edit': ['code'], # a GUI editor in the same entry is fine
}
To have a command behave the same in both modes, mark that command, the way
TEXT_EDITOR is marked:
{
'pattern': '*.log',
'view': {'command': ['less'], 'terminal': True}, # the desktop app's terminal too
'edit': {'command': ['code'], 'terminal': False}, # never takes the terminal
}
'terminal': True runs it in a terminal session in the desktop app; False
starts it in the background in terminal mode too, with its output in the log
pane. See Terminal.
Earlier drafts of this feature had a per-entry
'terminal': Trueflag. It was removed: it could not express one entry mixing a terminal viewer with a GUI editor, and failed unsafely — forgetting it onlesscorrupted the terminal. A leftoverterminalkey on an entry is ignored; the marking now belongs to each command, and an unmarked one still follows the backend.
Group related file patterns together:
{
'pattern': ['*.jpg', '*.jpeg', '*.png', '*.gif']
}
Instead of repeating the same configuration for each extension.
Use the pipe | operator to assign the same command to multiple actions:
{
'open|view': ['open', '-a', 'Preview']
}
This clearly shows that open and view use the same program, making the intent explicit.
Single pattern as string:
'pattern': '*.pdf'
Multiple patterns as list:
'pattern': ['*.mp4', '*.mov', '*.avi']
Old Format (Verbose):
FILE_ASSOCIATIONS = {
'*.jpg': {
'open': ['open', '-a', 'Preview'],
'view': ['open', '-a', 'Preview'],
'edit': ['open', '-a', 'Photoshop']
},
'*.jpeg': {
'open': ['open', '-a', 'Preview'],
'view': ['open', '-a', 'Preview'],
'edit': ['open', '-a', 'Photoshop']
},
# ... repeat for each extension
}
New Format (Compact):
FILE_ASSOCIATIONS = [
{
'pattern': ['*.jpg', '*.jpeg', '*.png', '*.gif'],
'open|view': ['open', '-a', 'Preview'],
'edit': ['open', '-a', 'Photoshop']
}
]
Reduction: 75% fewer lines!
FILE_ASSOCIATIONS entries are checked in order from top to bottom. This allows you to define specific rules before general rules, giving you fine-grained control over file handling.
When XeFM needs to find a program for a file and action:
First matching entry wins - but only if the action is present in that entry.
FILE_ASSOCIATIONS = [
# Specific: Test files
{
'pattern': 'test_*.py',
'open': ['pytest', '-v'],
'edit': ['vim']
},
# General: All Python files
{
'pattern': '*.py',
'open': ['python3'],
'view': ['less'],
'edit': ['vim']
}
]
Behavior:
test_main.py + open → pytest -v (matches first entry)test_main.py + view → less (first entry has no ‘view’, uses second entry)script.py + open → python3 (doesn’t match first pattern, uses second entry)FILE_ASSOCIATIONS = [
# Specific: README files with special viewer
{
'pattern': 'README*',
'view': ['glow'] # Markdown renderer
},
# General: All markdown files
{
'pattern': '*.md',
'open': ['typora'],
'view': ['less'],
'edit': ['vim']
}
]
Behavior:
README.md + view → glow (matches first entry)README.md + open → typora (first entry has no ‘open’, uses second entry)notes.md + view → less (doesn’t match first pattern, uses second entry)Once configured, XeFM will use these associations when you:
Enter uses the enter action. It never launches an external program.
Behavior:
'viewer' opens the built-in viewer; 'navigate' browses the file as an
archive; 'list' opens it as a file list; an XeFM action’s name runs that
action (Running an XeFM action); None does nothingopen_with_os, rather than
opening a viewer on content it cannot renderStep 6 is why images currently report *“No built-in viewer for photo.png —
press
Step 2 works the same way. A rule stops Enter from browsing an archive, and
'navigate' makes it browse a file XeFM does not recognize by name — a .docx,
or a zip with an extension of its own. The default associations already have
one such rule, for packages like .jar, .apk and .whl (see
Archives); add a name to it, or take one out.
{'pattern': '*.zip', 'enter': None}, # Enter on a .zip does nothing
{'pattern': '*.docx', 'enter': 'navigate'}, # Enter lists the .docx's XML
open_with_os uses the open action.
Behavior:
None, nothing is launched (this is how you stop a file type
from ever being handed to the OS)open / xdg-open / start)open_items_with_os does the same for every selected item (or the item under
the cursor). Items whose rule names the same program open in one launch.
More than 10 items ask before anything opens.
When you run view_file (File → Open With ▸ Viewer) on a file, XeFM uses the view action from file associations.
Behavior:
None, opens the built-in text viewerRemote and in-archive files always use the built-in viewer — an external program has no path on disk it could open.
view_files does the same for every selected file (or the file under the
cursor). Files whose rule names the same program open in one launch. The
built-in viewer shows one file at a time: of the files left for it, the first
opens and the rest are named in the log.
When you run edit_files (File → Open With ▸ Text Editor), XeFM edits the selected files — or the focused file when
nothing is selected — using the edit action from file associations.
Behavior (per file):
None, reports that no editor is configured and stopsTEXT_EDITOR config settingedit_file does the same for the file under the cursor alone, whatever is
selected.
Files that resolve to the same program are passed to it in one launch
(vim a.txt b.txt), so a multi-file edit is one editor session — a mixed
selection can still fan out to one launch per distinct editor.
Local files only; remote and in-archive paths are skipped (in a mixed selection they are skipped individually, with a log line each).
{
'pattern': ['*.jpg', '*.png'],
'open|view': ['open', '-a', 'Preview'], # Same for both
'edit': ['open', '-a', 'Photoshop'] # Different editor
}
Usage:
photo.jpg → Opens in Previewview_file on photo.jpg → Opens in Preview (same as Enter)edit_file on photo.jpg → Opens in Photoshop{
'pattern': '*.avi',
'open|view': ['open', '-a', 'VLC'],
'edit': None # No editor configured
}
Usage:
movie.avi → Opens in VLCview_file on movie.avi → Opens in VLCedit_file on movie.avi → Shows “No editor configured” message{
'pattern': '*.txt',
'open': ['open', '-e'], # TextEdit
'edit': ['vim'] # Terminal editor
# 'view' omitted - will use built-in text viewer
}
Usage:
readme.txt → Opens in TextEditview_file on readme.txt → Opens in built-in text viewer (with syntax highlighting)edit_file on readme.txt → Opens in vimNote: Omitting the view action allows XeFM to use the built-in text viewer for text files, which provides syntax highlighting and is optimized for viewing code and text files.
If a file has no configured association:
view_file: Opens the built-in text viewer, which reads the bytes — text is
shown with syntax highlighting, a binary shows a placeholderedit_file: Falls back to the TEXT_EDITOR config settingXeFM detects text by reading the bytes, not by looking at the extension.
There is deliberately no list of “text extensions” anywhere in XeFM: such a list
is wrong for files with no extension (Makefile, README), an unknown one, or
a misleading one — and inspecting the content gets all three right for free.
The built-in viewer decides like this:
utf-8, then latin-1, then cp1252[Binary file — cannot display as text] is
shownlatin-1 with replacement charactersThe rule of thumb across XeFM is detect capability from the bytes; configure preference by extension. Extensions decide which application you prefer — never whether a file is readable as text.
For the view action there are three cases, and two of them land in the same place:
view value |
Effect |
|---|---|
a command, e.g. ['less'] |
Launch that external viewer |
None |
Use the built-in viewer (text shown, binary → placeholder) |
| (no rule matches) | Same as None — the built-in viewer, via fallback |
So for view, None and “no rule at all” are equivalent. The distinction only
matters for open and edit, where None means “this action is
unavailable for this file type” and stops the fallback. Set 'view': None
explicitly only when you want to guarantee the built-in viewer even though a
later, more general entry might otherwise supply a command.
| Action | With association | No association — text | No association — binary |
|---|---|---|---|
| Enter | Built-in handler or configured open | Built-in viewer | Warns to use the open-externally key |
View (view_file) |
Configured viewer (or built-in if None) |
Built-in viewer | Built-in viewer shows placeholder |
Edit (edit_file) |
Configured editor | TEXT_EDITOR config |
TEXT_EDITOR config |
Beyond the configurable actions above, XeFM has two fixed gestures that hand a file to the operating system.
Action: open_with_os — the same key as the open action.
This is the deliberate-open tier described under
open_with_os: XeFM first looks for an
open command in your associations, and if there is none (and it is not
explicitly None) it falls back to the OS default application — open on
macOS, xdg-open on Linux, start on Windows. Selected files are opened; if
nothing is selected, the focused file is used. This handoff is not
configurable per file the way the open command is — it is whatever the OS
has registered for that type.
Action: reveal_in_os.
Opens the OS file manager with the item selected:
open -RexplorerThis action always uses the focused item, not the selection. When a directory is focused it is revealed in its parent (shown as a selected item), not opened to show its contents — useful for jumping out to the OS to drag-and-drop or reach a native context menu.
To pick a different application just this time, use Open With (File → Open With ▸ Choose App…). To run one of your own configured tools instead of the OS default, open the external programs menu with X (see External Programs).
Group multiple image extensions and use the same program for opening and viewing:
{
'pattern': ['*.jpg', '*.jpeg', '*.png', '*.gif'],
'open|view': ['open', '-a', 'Preview'],
'edit': ['open', '-a', 'Photoshop']
}
{
'pattern': ['*.mp4', '*.mov'],
'open|view': ['open', '-a', 'QuickTime Player'],
'edit': ['open', '-a', 'Final Cut Pro']
},
{
'pattern': '*.avi',
'open|view': ['open', '-a', 'VLC'],
'edit': None # No editor configured
}
{
'pattern': '*.pdf',
'open|view': ['open', '-a', 'Preview'],
'edit': ['open', '-a', 'Adobe Acrobat']
}
{
'pattern': '*.txt',
'open': ['open', '-e'], # TextEdit on macOS
'edit': ['vim']
# 'view' omitted - uses built-in text viewer
},
{
'pattern': ['*.py', '*.js'],
'open': ['open', '-a', 'Visual Studio Code'],
'edit': ['vim']
# 'view' omitted - uses built-in text viewer with syntax highlighting
}
File associations use wildcard pattern matching:
*.pdf - matches all PDF files*.jpg - matches all JPG files*.tar.gz - matches compressed tar archivesPattern matching is case-insensitive, so *.PDF and *.pdf are treated the same.
You can configure different programs for different platforms:
import platform
FILE_ASSOCIATIONS = []
if platform.system() == 'Darwin': # macOS
FILE_ASSOCIATIONS.append({
'pattern': ['*.jpg', '*.png'],
'open|view': ['open', '-a', 'Preview'],
'edit': ['open', '-a', 'Photoshop']
})
elif platform.system() == 'Linux':
FILE_ASSOCIATIONS.append({
'pattern': ['*.jpg', '*.png'],
'open': ['xdg-open'],
'view': ['eog'], # Eye of GNOME
'edit': ['gimp']
})
XeFM comes with default file associations for common file types:
You can override any of these defaults in your configuration file.
Same program for multiple actions: It’s common to use the same program for both ‘open’ and ‘view’ actions, especially for media files.
Specialized editors: Use the ‘edit’ action for specialized editing software that’s different from your viewing application.
No action available: Set an action to None if you don’t want that action available for a file type.
Test your commands: Make sure the commands work from your terminal before adding them to the configuration.
Use absolute paths: If a program isn’t in your PATH, use the absolute path to the executable.
Specific patterns first: Always put more specific patterns before general ones in your configuration.
Document your intent: Add comments to explain why entries are ordered a certain way.
If XeFM can’t find the program:
If the wrong program opens:
If an action doesn’t appear:
None)If a file doesn’t match the expected pattern:
*.ext format)Run the test to verify everything works:
python3 test/test_file_associations.py
doc/dev/FILE_ASSOCIATIONS_IMPLEMENTATION.mddoc/XEFM_USER_GUIDE.md