How to Configure Default Sort Type and Order in Superfile
Set default_sort_type and sort_order_reversed in ~/.config/superfile/config.toml to control whether file panels sort by name, size, date modified, type, or natural order, and whether the order is ascending or descending.
Superfile is a terminal-based file manager that stores user preferences in a TOML configuration file. To configure default sort type and order in superfile, you edit two fields defined in the ConfigType struct, which the application loads at startup and applies to every new file panel automatically.
Configurable Sort Fields in the Source Code
The available settings are declared in src/internal/common/config_type.go inside the ConfigType struct (see lines 81‑84). Superfile uses these two values to initialize sorting across all file panels.
default_sort_type
This integer field determines which attribute is used for sorting. The accepted values are mapped through the SortKind enum in src/internal/ui/sortmodel/types.go (lines 7‑12):
0— Name1— Size2— Date Modified3— Type4— Natural (human‑friendly)
The default value is 0 (Name).
sort_order_reversed
This boolean field controls the direction of the sort. When set to true, items are displayed in descending order. When false, the order is ascending. The default is false.
How to Edit the Configuration File
During startup, common.LoadConfigFile() (see src/internal/common/load_config.go) reads ~/.config/superfile/config.toml, validates that default_sort_type falls within the allowed range, and populates the global common.Config object.
To change the defaults, add or update these lines in your TOML file:
# ~/.config/superfile/config.toml
default_sort_type = 2 # 0=Name, 1=Size, 2=Date Modified, 3=Type, 4=Natural
sort_order_reversed = true # true = descending, false = ascending
Save the file and restart Superfile. The new values will be active on the next launch.
Runtime Code Path from Config to UI
Understanding how the setting travels from the config file to the rendered list helps confirm which files govern behavior.
Loading and Validation
The configuration loader in src/internal/common/load_config.go is responsible for parsing the TOML file and ensuring the sort type integer is valid. After parsing, the values live in common.Config.DefaultSortType and common.Config.SortOrderReversed.
Panel Initialization
When a file panel is created, the defaultFilePanel constructor in src/internal/ui/filepanel/model.go (lines 31‑33) passes the config values directly to New:
return New(
panelPath,
focused,
targetFile,
sortmodel.SortKind(common.Config.DefaultSortType), // ← sort kind
common.Config.SortOrderReversed) // ← sort order
This ensures every panel starts with the user-defined defaults.
Sorting Logic Implementation
The actual comparator is built in src/internal/ui/filepanel/sort.go. It uses the SortKind selected from the config together with the reversed flag to construct the sort.Slice comparator that orders the items in the panel.
Programmatically Working with Sort Settings
If you are extending Superfile or writing a plugin, you can read the loaded config values or even construct a panel with explicit sort parameters that ignore the config file.
Verify Config Values at Runtime
The following snippet prints the current defaults after the TOML file has been loaded:
package main
import (
"fmt"
"github.com/yorukot/superfile/src/internal/common"
)
func main() {
fmt.Printf("Default sort: %d (%s)\n",
common.Config.DefaultSortType,
[]string{"Name","Size","Date Modified","Type","Natural"}[common.Config.DefaultSortType])
fmt.Printf("Reverse order?: %v\n", common.Config.SortOrderReversed)
}
Running this after startup confirms the configuration has been parsed correctly.
Create a File Panel with Custom Sorting
You can also instantiate a panel programmatically with any SortKind and direction, bypassing the global config:
package main
import (
"github.com/yorukot/superfile/src/internal/ui/filepanel"
"github.com/yorukot/superfile/src/internal/ui/sortmodel"
)
func main() {
// Force a panel to start sorted by Size, descending
panel := filepanel.New(
"/home/user/Documents", // location
true, // focused
"", // no target file
sortmodel.SortBySize, // sort kind
true, // reverse order
)
// panel now uses the specified sort irrespective of the config file
_ = panel
}
This is useful for custom workflows where a specific panel needs fixed sorting behavior.
Summary
- To change the default sorting, edit
default_sort_typeandsort_order_reversedin~/.config/superfile/config.toml. default_sort_typeaccepts integers0through4, mapping to Name, Size, Date Modified, Type, and Natural.sort_order_reversedacceptstrue(descending) orfalse(ascending).- According to the yorukot/superfile source code, these fields are defined in
src/internal/common/config_type.goand loaded bycommon.LoadConfigFile()insrc/internal/common/load_config.go. - Each new file panel receives the values in
defaultFilePanelinsidesrc/internal/ui/filepanel/model.go. - The final comparator is built in
src/internal/ui/filepanel/sort.gousing theSortKindenum fromsrc/internal/ui/sortmodel/types.go.
Frequently Asked Questions
Where does Superfile store the default sort settings?
Superfile stores these settings in ~/.config/superfile/config.toml. The fields default_sort_type and sort_order_reversed are parsed at startup by common.LoadConfigFile() inside src/internal/common/load_config.go.
Can I sort files in descending order by default?
Yes. Set sort_order_reversed = true in the configuration file. This boolean is passed directly into the file panel constructor in src/internal/ui/filepanel/model.go and used to invert the comparator in src/internal/ui/filepanel/sort.go.
What happens if I set an invalid integer for default_sort_type?
The loader in src/internal/common/load_config.go validates the range of default_sort_type during initialization. You should keep the value between 0 and 4 to match the SortKind enum defined in src/internal/ui/sortmodel/types.go.
Do I need to restart Superfile after changing the sort config?
Yes. The TOML file is read once at startup. Changes take effect on the next launch because the configuration is loaded into the global common.Config object before any file panels are created.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →