feat: user configuration of editors by file extension#1197
feat: user configuration of editors by file extension#1197lazysegtree merged 5 commits intoyorukot:mainyorukot/superfile:mainfrom litvinov-git:configure-editors-by-file-extensionlitvinov-git/superfile:configure-editors-by-file-extensionCopy head branch name to clipboard
Conversation
WalkthroughAdds a new per-extension open-command configuration. ConfigType gains an OpenWith map; the file-open handler applies extension-based overrides on non-Windows platforms; config and docs receive a new [open_with] section and example. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10–15 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/superfile_config/config.toml (1)
149-158: Clarifyopen_withsemantics and reconsider the “must be at end” noteThe
[open_with]table and example mapping are consistent with the new feature, but two small clarity tweaks might help:
- Keys are interpreted as lowercased extensions without a leading dot (per
executeOpenCommand), so explicitly saying “use bare, lowercase extensions likemd,xopp,conf” here would avoid ambiguity.- The comment “MUST BE IN THE VERY END OF THE FILE BECAUSE TOML CANNOT CLOSE TABLES” is a bit strong; TOML tables don’t require an explicit close. If this is just a tooling or convention constraint, consider rephrasing so it doesn’t unnecessarily restrict adding future config fields after this section.
src/internal/handle_panel_movement.go (1)
70-105: Extension-based override looks correct; consider documenting/handling commands with argsThe new
open_withoverride logic is sound:
- Uses
filepath.Ext+strings.ToLower+TrimPrefixso lookups are case-insensitive and omit the dot.- Safe read from
common.Config.OpenWitheven when the map is nil.- Correctly leaves Windows behavior unchanged and applies overrides only on macOS/Linux.
One practical limitation: values like
pdf = "zathura --fork"in the config won’t work as expected becauseexec.Command(openCommand, filePath)treats the entire string as the executable, not as["zathura", "--fork"]. Only bare executable names (e.g."zathura","obsidian") are currently supported.Two options:
- Document this constraint in the config comments: “value must be a single executable name; arguments are not supported”.
- Or, if you want to support simple arguments, parse the value into command + args before calling
exec.Command, e.g.:parts := strings.Fields(ext_editor) if len(parts) > 0 { openCommand = parts[0] cmd := exec.Command(openCommand, append(parts[1:], filePath)...) // ... }This would make
open_withmore flexible without changing the external API.src/internal/common/config_type.go (1)
68-71: Config wiring forOpenWithis good; clarify expected key formatThe
OpenWithmap is correctly added and matches the[open_with]table inconfig.toml. To align with howexecuteOpenCommandnormalizes extensions, consider tightening the comment to specify that:
- Keys are file extensions without a leading dot, and
- Matching is case-insensitive (keys are treated as lowercase).
E.g. “Custom open commands by file extension (keys are bare, lowercase extensions like
md,xopp).”
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/internal/common/config_type.go(1 hunks)src/internal/handle_panel_movement.go(4 hunks)src/superfile_config/config.toml(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/internal/handle_panel_movement.go (1)
src/internal/common/default_config.go (1)
Config(11-11)
🔇 Additional comments (1)
src/internal/handle_panel_movement.go (1)
3-9: Import ofstringsis appropriateThe added
stringsimport is correctly used for extension normalization inexecuteOpenCommandand keeps the import set minimal.
|
I don't really see what problem this is a solution to, when, if you want to change default app, it can be changed system/user-wide with |
Implementing this feature was literally just as fast as creating a mime type. It is a basic file manager feature (nautilus has it and it does not generate new mime types, it just internally sets defaults). I saw many people asking for it as well. Being user friendly is nice overall. You shouldnt even have to know what mime types are to be able to use superfile just like any other file manager. |
|
Huh. I always thought nautilus and others changed the mime database -- didn't know it keeps a local one instead. I think it would be nice to also be able to put either an extention or a mime type in the config. This way, people who are not familiar with them can put the extention, and other people can have a single definition for files like JPEGs instead of requiring one for |
Yeah i agree, I will do that if my PR gets merged. I added what was necessary for me as a user, anything past that would be in vain if the owner doesnt think its needed. My vision for the complete feature is a separate keybind "open with", that would initiate a dialogue pop-up (like the one when creating a new item) with the following elements:
Local - would put this in the extension table in the config |
…efault config empty
lazysegtree
left a comment
There was a problem hiding this comment.
LGTM. This makes certain use cases easier.
|
@litvinov-git Let @yorukot check. I am good to merge it. |
Glad to hear that! Thank you for review and edtis |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [yorukot/superfile](https://github.com/yorukot/superfile) | minor | `v1.4.0` → `v1.5.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>yorukot/superfile (yorukot/superfile)</summary> ### [`v1.5.0`](https://github.com/yorukot/superfile/releases/tag/v1.5.0) [Compare Source](yorukot/superfile@v1.4.0...v1.5.0) This release brings major new features, including video and PDF preview support, multi-column file panels, and configurable navigation, alongside significant code refactoring and comprehensive bug fixes. #### Install: [**Click me to know how to install**](https://github.com/yorukot/superfile?tab=readme-ov-file#installation) #### Highlights - Added video and PDF preview support via loading the first frame/page as an image. Thanks [@​Yassen-Higazi](https://github.com/Yassen-Higazi) for the implementation <details><summary>Screenshots</summary> <p> <img width="951" height="596" alt="image" src="https://github.com/user-attachments/assets/6edfa9c2-ebcd-4622-a115-f71fa533b3e1" /> <img width="949" height="594" alt="image" src="https://github.com/user-attachments/assets/8d15fa46-5178-422d-8eea-455cac31fdd0" /> </p> </details> - Multi-column file panel view with date/size/permission columns. Thanks [@​xelavopelk](https://github.com/xelavopelk) for the implementation <details><summary>Screenshots</summary> <p> <img width="420" height="264" alt="image" src="https://github.com/user-attachments/assets/e172f1e8-c2a5-42d2-8eeb-62e721f61a4f" /> </p> </details> - Configurable fast navigation in the Filepanel. See this MR for more details: [#​1220](yorukot/superfile#1220) - You can now configure `spf` to open files with specific extensions with your choice of editor application. Thanks [@​litvinov-git](https://github.com/litvinov-git) for the implementation See this MR for more details: [#​1197](yorukot/superfile#1197) - Terminal stdout support for shell commands - Allow launching with the filename. `spf /a/b/c.txt` will launch in `/a/b` with `c.txt` as the selected file. - Various bug fixes, including modal confirmations, layout issues, and race conditions. See 'Detailed Change Summary' ##### Internal Updates - Separated FilePanel and FileModel into a dedicated package for better code organization - Comprehensive end-to-end testing with layout fixes - Enhanced dimension validation and sidebar fixes - Updated multiple dependencies including Astro, Go toolchain, and linters - Added gosec linter and MND linter with magic number cleanup #### Detailed Change Summary <details><summary>Details</summary> <p> ##### Update - allow hover to file [`#1177`](yorukot/superfile#1177) by @​lazysegtree - show count selected items in select mode [`#1187`](yorukot/superfile#1187) by @​xelavopelk - Add icon alias for kts to kt [`#1153`](yorukot/superfile#1153) by @​nicolaic - link icon and metadata [`#1171`](yorukot/superfile#1171) by @​xelavopelk - user configuration of editors by file extension [`#1197`](yorukot/superfile#1197) by @​litvinov-git - add video preview support [`#1178`](yorukot/superfile#1178) by @​Yassen-Higazi - Add pdf preview support [`#1198`](yorukot/superfile#1198) by @​Yassen-Higazi - Add icons in pinned directories [`#1215`](yorukot/superfile#1215) by @​lazysegtree - Enable fast configurable navigation [`#1220`](yorukot/superfile#1220) by @​lazysegtree - add Trash bin to default directories for Linux [`#1236`](yorukot/superfile#1236) by @​lazysegtree - add terminal stdout support for shell commands [`#1250`](yorukot/superfile#1250) by @​majiayu000 - More columns in file panel (MVP) [`#1268`](yorukot/superfile#1268) by @​xelavopelk ##### Bug Fix - only calculate checksum on files [`#1119`](yorukot/superfile#1119) by @​nikero41 - Linter issue with PrintfAndExit [`#1133`](yorukot/superfile#1133) by @​xelavopelk - Remove repeated os.ReadDir calls [`#1155`](yorukot/superfile#1155) by @​lazysegtree - Disable COPYFILE in macOS [`#1194`](yorukot/superfile#1194) by @​lazysegtree - add missing hotkeys to help menu [`#1192`](yorukot/superfile#1192) by @​lazysegtree - Fetch latest version automatically [`#1127`](yorukot/superfile#1127) by @​lazysegtree - Use async methods to prevent test race conditions [`#1201`](yorukot/superfile#1201) by @​lazysegtree - update metadata and process bar sizes when toggling footer [`#1218`](yorukot/superfile#1218) by @​lazysegtree - File panel dimension management [`#1222`](yorukot/superfile#1222) by @​lazysegtree - Layout fixes with full end-to-end tests [`#1227`](yorukot/superfile#1227) by @​lazysegtree - Fix flaky tests [`#1233`](yorukot/superfile#1233) by @​lazysegtree - modal confirmation bug with arrow keys [`#1243`](yorukot/superfile#1243) by @​lazysegtree - small file panel optimization [`#1241`](yorukot/superfile#1241) by @​xelavopelk - use ExtractOperationMsg for extraction [`#1248`](yorukot/superfile#1248) by @​lazysegtree - skip open_with from missing field validation [`#1251`](yorukot/superfile#1251) by @​lazysegtree - border height validation fixes [`#1267`](yorukot/superfile#1267) by @​lazysegtree - fix case with two active panes [`#1271`](yorukot/superfile#1271) by @​xelavopelk - help model formatting [`#1277`](yorukot/superfile#1277) by @​booth-w ##### Optimization - simplify renameIfDuplicate logic [`#1100`](yorukot/superfile#1100) by @​sarff - separate FilePanel into dedicated package [`#1195`](yorukot/superfile#1195) by @​lazysegtree - File model separation [`#1223`](yorukot/superfile#1223) by @​lazysegtree - Dimension validations [`#1224`](yorukot/superfile#1224) by @​lazysegtree - layout validation and sidebar dimension fixes [`#1228`](yorukot/superfile#1228) by @​lazysegtree - user rendering package and removal of unused preview code [`#1245`](yorukot/superfile#1245) by @​lazysegtree - user rendering package for file preview [`#1249`](yorukot/superfile#1249) by @​lazysegtree ##### Documentation - update Fish shell setup docs [`#1142`](yorukot/superfile#1142) by @​wleoncio - fix macOS typo [`#1212`](yorukot/superfile#1212) by @​wcbing - stylistic and linguistic cleanup of config documentation [`#1184`](yorukot/superfile#1184) by @​ninetailedtori ##### Dependencies - update astro monorepo [`#1010`](yorukot/superfile#1010) by @​renovate[bot] - update starlight-giscus [`#1020`](yorukot/superfile#1020) by @​renovate[bot] - bump astro versions [`#1138`](yorukot/superfile#1138), [`#1157`](yorukot/superfile#1157), [`#1158`](yorukot/superfile#1158) by @​dependabot[bot], @​renovate[bot] - bump vite [`#1134`](yorukot/superfile#1134) by @​dependabot[bot] - update setup-go action [`#1038`](yorukot/superfile#1038) by @​renovate[bot] - update expressive-code plugins [`#1189`](yorukot/superfile#1189), [`#1246`](yorukot/superfile#1246) by @​renovate[bot] - update sharp [`#1256`](yorukot/superfile#1256) by @​renovate[bot] - update fontsource monorepo [`#1257`](yorukot/superfile#1257) by @​renovate[bot] - update urfave/cli [`#1136`](yorukot/superfile#1136), [`#1190`](yorukot/superfile#1190) by @​renovate[bot] - update astro / starlight / ansi / toolchain deps [`#1275`](yorukot/superfile#1275), [`#1278`](yorukot/superfile#1278), [`#1280`](yorukot/superfile#1280) by @​renovate[bot] - update python and go versions [`#1276`](yorukot/superfile#1276), [`#1191`](yorukot/superfile#1191) by @​renovate[bot] - update golangci-lint action [`#1286`](yorukot/superfile#1286) by @​renovate[bot] ##### Misc - update CI input names [`#1120`](yorukot/superfile#1120) by @​nikero41 - Everforest Dark Hard theme [`#1114`](yorukot/superfile#1114) by @​fzahner - migrate tutorial demo assets to local [`#1140`](yorukot/superfile#1140) by @​yorukot - new logo asset [`#1145`](yorukot/superfile#1145) by @​nonepork - mirror repository to codeberg [`#1141`](yorukot/superfile#1141) by @​yorukot - sync package lock [`#1143`](yorukot/superfile#1143) by @​yorukot - bump golangci-lint version [`#1135`](yorukot/superfile#1135) by @​lazysegtree - add gosec linter [`#1185`](yorukot/superfile#1185) by @​lazysegtree - enable MND linter and clean magic numbers [`#1180`](yorukot/superfile#1180) by @​lazysegtree - skip permission tests when running as root [`#1186`](yorukot/superfile#1186) by @​lazysegtree - release v1.4.1-rc [`#1203`](yorukot/superfile#1203) by @​lazysegtree - 1.5.0-rc1 housekeeping changes [`#1264`](yorukot/superfile#1264) by @​lazysegtree </p> </details> #### New Contributors * @​fzahner made their first contribution in yorukot/superfile#1114 * @​sarff made their first contribution in yorukot/superfile#1100 * @​nicolaic made their first contribution in yorukot/superfile#1153 * @​Yassen-Higazi made their first contribution in yorukot/superfile#1178 * @​ninetailedtori made their first contribution in yorukot/superfile#1184 * @​litvinov-git made their first contribution in yorukot/superfile#1197 * @​wcbing made their first contribution in yorukot/superfile#1212 * @​majiayu000 made their first contribution in yorukot/superfile#1250 **Full Changelog**: <yorukot/superfile@v1.4.0...v1.5.0> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi44MC4xIiwidXBkYXRlZEluVmVyIjoiNDIuODAuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6Om1pbm9yIl19-->
I added user configuration of default commands (apps/editors) to open files with specific file extensions.
In the very end of the
config.toml, there is a table [open_with] containing entries of the format:In
config_type.go, this table is read as a string to string map:In handle_panel_movement.go, I changed the
executeOpenCommand()function:The comments are self-explanatory. I implemented the feature only for linux and mac, plan to do it for windows later (i dont know how cmd works there(( )
Tested on Arch Linux, works perfectly fine there. I dont have any other machines to test on unfortunately.
Why is this needed:
xdg-openand other default openers do not properly recognize specific file types (like xournals xopp and such), also some people want to open toml and txt with different editors, butxdg-openwould open them with the same one. There are other examples.If you find any issues, please contact me. I am very eager to contribute and will fix anything)
Summary by CodeRabbit
New Features
Documentation
Config
✏️ Tip: You can customize this high-level summary in your review settings.