俺がずっと求めていたコマンド
— k1LoW (@k1LoW) 2019年12月24日
pt 'def logged_in?' . $(bundle show --paths) --color --group | less -R
$ pt 'def logged_in?' . $(bundle show --paths) --color --group | less -R
ptは pt PATTERN [PATH1] [PATH2] ...
と複数パスを指定できるので、カレントディレクトリ .
と bundle show --paths
で得たgemのパス一覧を渡すことで検索できました。
bundle show --paths
便利。
ということで忘れないようにメモエントリ。
helm-ag-project-root-with-bundle-paths
"helm" といったらクラウドネイティブだったりしますが、使っていたhelm-agのコマンドにptを設定しているので、そのままbundle installされたgemのソースコードも含めてプロジェクトのソースを検索できる関数をしたためておきました。
(require 'helm-ag) (custom-set-variables '(helm-ag-base-command "pt -e --nocolor --nogroup")) (defun helm-ag-project-root-with-bundle-paths () "helm-ag-project-root with bundle paths." (interactive) (helm-ag--init-state) (let ((rootdir (helm-ag--project-root)) (bundle-paths (split-string (shell-command-to-string "bundle show --paths") "\n"))) (let ((helm-ag--default-directory default-directory) (helm-ag--default-target (add-to-list 'bundle-paths rootdir))) (helm-ag--query) (helm-attrset 'search-this-file nil helm-ag-source) (helm-attrset 'name (helm-ag--helm-header helm-ag--default-directory) helm-ag-source) (helm :sources '(helm-ag-source) :buffer "*helm-ag-project-root-with-bundle-paths*" :keymap helm-ag-map :history 'helm-ag--helm-history))))
以上です