0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

peco で npm-scripts を簡単に実行する

Last updated at Posted at 2022-10-19

image.png

pecoでnpm-scriptsを超簡単に実行したい - Qiita のような先人がいるけど、この方法だと表示されるのはコマンド名だけで、コマンドの内容も表示したかったので、改良版を作った。 要 jq 。

適当な短いエイリアスでも付けて使ってください。

.bashrc
npm_run_peco() {
    local selected=$(
        cat "./package.json" \
        | jq -r '.scripts | to_entries | map("\(.key)#\(.value)") | .[]' \
        | column -t -s# \
        | peco \
        | perl -pe 's/ +.+$//'
    );
    if [ -n "$selected" ]; then
        yarn run $selected;
    fi
}

zsh 利用者でキーバインドで実行したい人は下記も追記。

.zshrc
zle -N npm_run_peco
bindkey '^n' npm_run_peco
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?