0

greg で -l フラグを使用してファイルのリストを取得するのはかなり一般的です。リストを出力するだけでなく、見つかったすべてのファイルをすぐに崇高に開く方法が大好きです(何らかの方法で subl コマンドを使用すると思います)。

私の現在のワークフロー:

grep --include=*.php -R -l "tribe_events_event_classes" .

どの出力:

./plugins/events-calendar-pro/views/day/loop.php
./plugins/events-calendar-pro/views/map/loop.php
./plugins/events-calendar-pro/views/photo/loop.php
./plugins/events-calendar-pro/views/widgets/mini-calendar/list.php
./plugins/the-events-calendar/lib/tribe-template-factory.class.php
./plugins/the-events-calendar/public/template-tags/general.php
./plugins/the-events-calendar/views/list/loop.php
./plugins/the-events-calendar/views/month/single-event.php
./themes/roots/tribe-events/day/loop.php

次に、通常、ファイルを1つずつコピーして貼り付けます。

subl ./plugins/events-calendar-pro/views/day/loop.php
subl ./plugins/events-calendar-pro/views/map/loop.php
etc...

これを行うには、ここがより効率的な方法でなければならないことを私は知っています。

4

2 に答える 2

4

これを行う最も簡単な方法は次のとおりです。

subl `grep --include=*.php -R -l "tribe_events_event_classes" .`

(バッククォートに注意してください)。

または:

for file in `grep --include=*.php -R -l "tribe_events_event_classes" .`; do
    subl $file
done

編集

バッククォートはうまく入れ子にならないため、コマンド置換を使用することをお勧めします。

subl $(grep --include=*.php -R -l "tribe_events_event_classes" .)
于 2013-07-30T16:36:33.063 に答える
0

これは、bash スクリプトでうまく解決できます。これはテストされていない概念です(微調整が必​​要な場合があります):

#!/bin/bash

files=()

while grep --include=*.php -R -l "tribe_events_event_classes" .; do
  files += ("$REPLY")
done

for file in "${files[@]}"; do 
  subl $file 
done
于 2013-07-30T16:35:11.277 に答える