- TypeScript 92%
- JavaScript 7%
- Shell <1%
pick-power #
pick-power makes "pick one or many things" a solved problem for applications that need interactive selection.
Why this exists #
Most programs rebuild picker support from scratch:
- custom formatting per tool
- fragile parsing of selected rows
- duplicate logic for different picker frontends
- inconsistent keybindings, multi-select, and execution behavior
pick-power provides a shared model so programs can offer rich picking without inventing another one-off protocol.
Requirements #
Canonical row model #
Applications must be able to provide typed rows with stable identity so that selections can be unambiguously parsed back regardless of which picker frontend was used.
Rows must support at minimum:
- a unique identifier
- a display label
- optional description
- optional raw value
- arbitrary metadata
Picker adapters #
The system must support multiple picker frontends, including:
- inline/terminal pickers (no external process)
- terminal-based fuzzy finders
- graphical menus (Wayland, X11)
Each adapter must describe:
- how to invoke the picker
- what capabilities it supports (single select, multi-select, preview, custom key actions, etc.)
- how to parse output back into selected row identities
The system must gracefully degrade features when a given picker lacks capability support.
Output formats #
Applications must be able to request selections in standard output formats for integration with external tools and pipelines.
Action model #
Selections must be separate from actions. The library returns selected rows; callers decide what to do with them.
Optional action hooks should support:
- execute selected item
- custom key actions
- cancel, retry, or multi-step selection flows
Design principles #
- protocol-first: stable contracts before UI details
- deterministic parsing: never guess selected row identity
- graceful fallback: degrade features by adapter capability
- composable: apps can use full picker orchestration or only formatting/parsing helpers
- zero lock-in: bring your own picker process when needed
Current API surface #
The core library exports a layered API already:
emitRows(...)- stream rows in picker-safe formatspickerArgs(...)- map requested behavior to picker flagsbuildLaunchSpec(...)/launchPicker(...)- spawn-shaped launch contractspipePicker(...)- launch picker and stream rows into stdinpick(...)- managed pick session that returns typed selectionsparsePickerArgs(...)/gunshiPickerPlugin(...)- optional CLI integration helpers
Quick example #
import { pick } from 'pick-power'
const selection = await pick({
rows: [
{ id: 'a', label: 'Alpha' },
{ id: 'b', label: 'Beta' },
],
picker: 'fzf',
delimiter: '\\t',
multi: true,
})
console.log(selection.ids)
pick-power preserves identity separately from display text and fails loudly when selection decoding is ambiguous.
Environment variables #
PICKER- default picker command (can include embedded args)PICKER_OPTIONS- extra picker options appended to launch argsPICKER_DISABLE- comma-separated feature disables (for exampleprompt,preview)
Target use cases #
- command history selectors
- media pickers
- package/version pickers
- git branch/commit selectors
- cloud resource selectors
- TUI workflows that need optional GUI picker handoff
Examples #
See example/README.md for compositional flows including managed picks, emitted-row pipelines, launch-spec inspection, and shell scripts with inline Node composition.
License #
MIT