Skip to content

feat(filepicker): add support for abstracted filesystem io/fs.FS [v2]#954

Open
dolmen wants to merge 1 commit intocharmbracelet:mainfrom
dolmen-go:filepicker-add-support-for-fs.FS-v2
Open

feat(filepicker): add support for abstracted filesystem io/fs.FS [v2]#954
dolmen wants to merge 1 commit intocharmbracelet:mainfrom
dolmen-go:filepicker-add-support-for-fs.FS-v2

Conversation

@dolmen
Copy link
Copy Markdown

@dolmen dolmen commented Apr 13, 2026

Add an optional io/fs.FS to filepicker's model to allow to browse an abstracted filesystem as an alternative to the full filesystem exposed by the os package.

The filepicker API is extended (and generalized thanks to io/fs.FS), without any breaking change.

This allows for example to browse limited a subdirectory by using os.Root (go1.24+):

fp := filepicker.New()
root, _ := os.OpenRoot(dir)
fp.FS = root.FS()

Fixes #815.
Replaces #759 (which was for v1).
Discussion: #886.

Full support of symlinks is implemented. To resolve symlinks we use io/fs.ReadLink introduced with Go 1.25, but fallback to an internal implementation if the FS doesn't implement it.

By the way, references to os types and constants which are aliases to same symbols in io/fs are replaced: os.Mode*, os.DirEntry.

Example

See package github.com/dolmen-go/iofs-shell.

Runnable example:

$ go run github.com/dolmen-go/iofs-shell/examples/browse-zip@main <file>.zip

To use my fork right now:

$ go mod edit -replace=charm.land/bubbles/v2=github.com/dolmen-go/bubbles.fork/v2@v2.1.1-0.20260413112845-8dad07786efc
  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

Add an optional io/fs.FS to filepicker's model to allow to browse an
abstracted filesystem instead of the full filesystem exposed by the 'os'
package.

To resolve symlinks we use io/fs.ReadLink introduced with Go 1.25, but
fallback to an internal implementation if the FS doesn't implement it.

By the way, references to os types and constants (which nowadays are
aliases to same symbols in io/fs) are replaced: os.Mode*, os.DirEntry.

Fixes charmbracelet#815.
Replaces charmbracelet#759.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

filepicker: Allow for different filesystems to be used

1 participant