LoginSignup
1
0

More than 1 year has passed since last update.

Makefileのコマンドを「m」で選択実行できるようにする

Posted at

こうなる

$ m

ってしたら

QUERY>                                                                                IgnoreCase [5 (1/1)]
help           ヘルプコマンド                                                                             
docker-bash    コンテナにbashで入る
docker-attach  コンテナで実行中のコマンドにattach
docker-logs    コンテナのログを見る
open-bookmark  ブックマーク

こんな感じで出る

環境

peco
mac
zsh

Makefileのコマンド一覧を出す。
https://qiita.com/MiuraKatsu/items/9499fd95106b75964e4a
こちらをそのまま

.PHONY: help
#: ヘルプコマンド
help:
	@grep -A1 -E "^#:" Makefile \
	| grep -v -- -- \
	| sed 'N;s/\n/###/' \
	| sed -n 's/^#: \(.*\)###\(.*\):.*/\2###\1/p' \
	| column -t  -s '###'

あとはこのコマンドの結果をpecoに渡して戻ってきたやつを実行する。

.zshrc
# m で make helpを選択実行
function makefile-select-and-run() {
  [ ! -e Makefile ] && echo "NotFound Makefile" && return
  KEY=$(make help | peco | awk '{print $1}')
  [ -n "$KEY" ] && make $KEY
}
alias m=makefile-select-and-run

おわりに

同僚に教えていただいたやり方。感謝!

1
0
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
1
0