Yarn package.json script picker (fzf)
Optional zsh functions to fuzzy-pick yarn scripts from package.json — high ROI, no history/keybind changes
Yarn package.json script picker (fzf)
Why this exists
Commands like yarn serve:backend-api, yarn serve:gograb-space, etc. share a long prefix. History search is fine but structured picking from package.json is faster and stays correct when scripts are added or renamed.
This adds optional shell functions and aliases. It does not change Ctrl+R, arrow keys, or HISTFILE behavior.
Requirements
fzf(already used elsewhere in this zsh setup)jqornodeto readpackage.json
What was added (repo)
| Path | Role |
|---|---|
tools/scripts/system/zsh-yarn-scripts-fzf.zsh |
Defines yarn_scripts_fzf, yarn_serve_scripts_fzf, aliases yscripts, yserve |
Activation (already wired if you use the default block)
~/.zshrc should contain a guarded source (only loads if the file exists):
export GSPACE1_ROOT="${GSPACE1_ROOT:-$HOME/developer/repos-gspace/gspace1}"
_YARN_FZF_ZSH="${GSPACE1_ROOT}/tools/scripts/system/zsh-yarn-scripts-fzf.zsh"
[[ -r "$_YARN_FZF_ZSH" ]] && source "$_YARN_FZF_ZSH"
unset _YARN_FZF_ZSH
If your clone lives elsewhere, set GSPACE1_ROOT before this block or edit the default path.
Usage
From a directory that has package.json (e.g. gspace1 root):
| Command | Behavior |
|---|---|
yserve |
Open fzf with initial query serve: — picks among serve:* script names, then runs yarn <name> (same as your usual history lines) |
yscripts |
List all scripts from ./package.json in fzf, then yarn <name> |
yarn_scripts_fzf |
Same as yscripts; optional args: [path/to/package.json] [fzf-query] |
yarn_serve_scripts_fzf |
Same as yserve; optional arg: path to package.json |
Examples:
cd ~/developer/repos-gspace/gspace1
yserve
# or all scripts:
yscripts
# app-level package.json:
yarn_scripts_fzf apps/some-app/package.json
Cancel fzf with Esc — nothing runs.
Safety / behavior guarantees
- Additive only: new functions and aliases; no overrides of existing widgets or
bindkey. - Explicit run: only
yarn <script>after you confirm a fzf selection (normal yarn script invocation). - No history file changes: does not rewrite
HISTFILE/SESSION_HISTFILElogic. - Missing tools: if
fzforjq/nodeis missing, the function prints an error and returns; other shell behavior is unchanged.
Revert (disable completely)
- Open
~/.zshrc. - Find the block marked
YARN_SCRIPTS_FZF_BEGIN/YARN_SCRIPTS_FZF_END(or search forzsh-yarn-scripts-fzf.zsh). - Comment out or delete the whole block (from the comment header through
unset _YARN_FZF_ZSH). - Run
exec zshor open a new terminal.
Optional: remove aliases from an active session:
unalias yserve yscripts 2>/dev/null
See also
- Changelog entry:
zshrc-latest-changes.md(Change 5). - Index:
README.mdin this folder.