5
4

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 5 years have passed since last update.

gulp 実行時のタスク名をタブキーで補完

Last updated at Posted at 2015-07-11

gulp にはタスク名をタブキーで補完できるようにスクリプトが用意されていて、
.bashrc に下の一行を追記すれば node_modules/gulp/completion/bash が実行され
タブキーによるタスク名の補完が出来ます。

.bashrc
eval "$(gulp --completion=bash)"

参照:
https://github.com/gulpjs/gulp/blob/master/completion/README.md

しかし、タブキーが押されるたびに毎回内部では gulp --tasks-simple が実行されているので私の環境では非常に重いです。

そこで、自前ででっち上げました

.bashrc
function _gulp_completions() {
    # The currently-being-completed word.
    local cur="${COMP_WORDS[COMP_CWORD]}"
    #Grab tasks
    local compls=$(grep task gulpfile.js | sed -e 's/gulp.task(.//' -e 's/.,.*//' -e '/default/d')
    # Tell complete what stuff to show.
    COMPREPLY=($(compgen -W "$compls" -- "$cur"))
}

complete -o default -F _gulp_completions gulp

これで gulp <TAB><TAB> と打てばタスク一覧が表示され、
先頭の一文字以上打って <TAB> を押せば残りを補完してくれます。
サクサク補完されるので、作業効率も上がります。

5
4
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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?