Skip to content

File Picker

A filesystem navigator and file picker for Ink 5. Navigate directories, select files, and filter by extension.

Install

Terminal window
npm install @matthesketh/ink-file-picker

Usage

import React from 'react';
import { render } from 'ink';
import { FilePicker } from '@matthesketh/ink-file-picker';
function App() {
return (
<FilePicker
extensions={['.ts', '.tsx']}
onSelect={(filePath) => {
console.log('Selected:', filePath);
}}
onCancel={() => {
console.log('Cancelled');
}}
/>
);
}
render(<App />);

Props

PropTypeDefaultDescription
initialPathstringprocess.cwd()Starting directory
extensionsstring[]undefinedFilter files by extension (e.g. ['.ts', '.tsx'])
showHiddenbooleanfalseShow hidden files (starting with .)
maxVisiblenumber15Maximum visible items in the windowed list
onSelect(path: string) => voidrequiredCalled when a file is selected
onCancel() => voidundefinedCalled when Escape is pressed

Keybindings

KeyAction
j / DownMove selection down
k / UpMove selection up
EnterOpen directory or select file
BackspaceGo up one directory
EscapeCancel

Features

  • Folders listed first with prefix, files with · prefix
  • File sizes shown in dim text
  • Windowed scrolling with maxVisible limit and scroll indicators
  • Extension filtering (directories always shown)
  • Hidden file toggle

License

MIT