ack使ãæ¹ã¡ã¢
â»2010/4/18ããã¤ãã使ã£ãä¾ãã追è¨ãã¾ãã
å
ã
é±ããããããvimä¸ããackã使ã£ãããã£ã¬ã¯ããªä»¥ä¸ã®ãã¡ã¤ã«ä¸æ¬ç½®æããè¡ãvimã¹ã¯ãªããæ¸ããããã¦ã¾ããã
ã§ããªãããã£ããããªãã®ã§å
¬éãããã©ããã¯å¾®å¦â¦
ã¡ãªã¿ã«ackã¯ç°¡åã«è¨ãã¨ãfind+grepããä¸çºå®è¡ãããããªãã®ã§ãã
ãã¤ã©ã¤ããªã©ã対å¿ãã¦ããããä»ã®ã³ãã³ãã«çµæããã¤ããã¦æ¸¡ãããããã®ã«ã使ããã®ã§
æ¿ãã便å©ã
ã§ããã®ããã«ããããack調æ»ãã¦ãã®ã§ããã
æ¥æ¬èªã®èª¬æããã¾ããªãã£ãã®ã§ä½¿ãæ¹ãªã©ãã¡ã¢æ¸ããã¦ããã¾ãã
ã¡ãªã¿ã«ã以ä¸ã®å®è¡ä¾ã«ã¤ãã¦ã¯plaggerã®ã½ã¼ã¹ãæ¤ç´¢ããçµæã«ãªã£ã¦ãã¾ãã
ã¤ã³ã¹ãã¼ã«
cpan App::Ack
ã§okã
yumã¨ãapt-getã§ãããã±ã¼ã¸ããããã§ãããåä¸ã¹ã¯ãªããã¨ãã¦ãæä¾ããã¦ããããã§ãã
詳ããã¯こちらã®How To Install Ackããåç
§ä¸ããã
åºæ¬çãªä½¿ãæ¹
ack ãã¿ã¼ã³ããã [ãã¡ã¤ã«åï¼çç¥å¯ï¼]
ex)ã«ã¬ã³ããã£ã¬ã¯ããªä»¥ä¸ãã decode_content ã¨ãããµãã«ã¼ãã³ãæ¤ç´¢
ack decode_content
å®è¡çµæ*1
assets/plugins/Filter-FindEnclosures/ustream.pl 2:use Plagger::Util qw( decode_content ); assets/plugins/Filter-FindEnclosures/youtube.pl 2:use Plagger::Util qw( decode_content ); 25: $args->{content} = decode_content($res); lib/Plagger/FeedParser.pm 46: $content = Plagger::Util::decode_content($res); ...
ãã¡ã¤ã«çµãè¾¼ã¿ã«é¢ãããªãã·ã§ã³*2
-f
ãã¿ã¼ã³æ¤ç´¢ããªãã§å¯¾è±¡ãã¡ã¤ã«ã®ã¿åºå*3
ex)ã«ã¬ã³ããã£ã¬ã¯ããªä»¥ä¸ãã perlãã¡ã¤ã«ã®ä¸è¦§ã表示
ack -f --perl
å®è¡çµæ
assets/plugins/CustomFeed-Script/dave-trailer-HD.pl assets/plugins/CustomFeed-Script/domain-expire.pl assets/plugins/CustomFeed-Script/jp-playstation-store.pl ...
-a
ãã¹ã¦ã®ãã¡ã¤ã«ã¿ã¤ããæ¤ç´¢å¯¾è±¡ã«ãã*4
--perl
perlãã¡ã¤ã«ã®ã¿å¯¾è±¡ã
ä»ã«æå®åºæ¥ããã¡ã¤ã«ã¿ã¤ãã«ã¤ãã¦ã¯ ãack --help-typesãã®å®è¡çµæããåç
§ä¸ããã
-G regex
対象ãã¡ã¤ã«åã®ãã¿ã¼ã³ãæå®ï¼æ£è¦è¡¨ç¾ï¼ã
ex)ã«ã¬ã³ããã£ã¬ã¯ããªä»¥ä¸ãã ãã¹åãã"/Filter/"ãã«ä¸è´ãããã¡ã¤ã«ããã
ãdecode_content ã¨ãããµãã«ã¼ãã³ãæ¤ç´¢
ack decode_content -G /Filter/
å®è¡çµæ
lib/Plagger/Plugin/Filter/EntryFullText.pm 11:use Plagger::Util qw( decode_content ); 115: $args->{content} = decode_content($res); lib/Plagger/Plugin/Filter/FindEnclosures.pm 6:use Plagger::Util qw( decode_content ); 187: return decode_content($res);
ãã¿ã¼ã³ãããã«é¢ãããªãã·ã§ã³
-w
åèªã®å®å
¨ããã
-i
大æåå°æåãåºå¥ããªã
åºåçµæã«é¢ãããªãã·ã§ã³
-l
ãã¿ã¼ã³ããããããã¡ã¤ã«åã®ã¿åºå
ex)
ack decode_content -l
å®è¡çµæ
assets/plugins/Filter-FindEnclosures/ustream.pl assets/plugins/Filter-FindEnclosures/youtube.pl lib/Plagger/FeedParser.pm lib/Plagger/Plugin/CustomFeed/2chSearch.pm lib/Plagger/Plugin/CustomFeed/BloglinesCitations.pm lib/Plagger/Plugin/CustomFeed/GoogleNews.pm lib/Plagger/Plugin/CustomFeed/MixiDiarySearch.pm lib/Plagger/Plugin/CustomFeed/PerlMonks.pm lib/Plagger/Plugin/CustomFeed/Simple.pm lib/Plagger/Plugin/Filter/EntryFullText.pm lib/Plagger/Plugin/Filter/FindEnclosures.pm lib/Plagger/Plugin/Summary/TrackbackRDF.pm lib/Plagger/Util.pm
-C
ãããããè¡ã®åå¾è¡¨ç¤ºè¡æ°ãæå®
ex)ãããããåå¾ï¼è¡ã表示
ack -C 5 decode_content
å®è¡çµæ
assets/plugins/Filter-FindEnclosures/ustream.pl 1-# author: yappo, typester 2:use Plagger::Util qw( decode_content ); 3- 4-sub handle { 5- my ($self, $url) = @_; 6- $url =~ qr!http://(?:www.)?ustream.tv/recorded/.+!; 7-} assets/plugins/Filter-FindEnclosures/youtube.pl 1-# author: mizzy 2:use Plagger::Util qw( decode_content ); 3- 4-sub handle { 5- my ($self, $url) = @_; 6- $url =~ qr!http://(?:(?:au|br|ca|fr|de|us|hk|ie|it|jp|mx|nl|nz|pl|es|tw|gb|www)\.)?youtube\.com/(?:watch(?:\.php)?)?\?v=.+!; 7-} -- ...
--nogroup
ã--noheadingãã¨ã--nobreakããæå®ããã®ã¨åã表示ï¼è¦ãç®ã®å¤æ´ï¼
ã¡ãªã¿ã«ããã©ã«ãã¯--groupãæå®ãã表示ã«ãªã£ã¦ããã
ex)
ack decode_content --nogroup
å®è¡çµæ
assets/plugins/Filter-FindEnclosures/ustream.pl:2:use Plagger::Util qw( decode_content ); assets/plugins/Filter-FindEnclosures/youtube.pl:2:use Plagger::Util qw( decode_content ); assets/plugins/Filter-FindEnclosures/youtube.pl:25: $args->{content} = decode_content($res); lib/Plagger/FeedParser.pm:46: $content = Plagger::Util::decode_content($res); lib/Plagger/Plugin/CustomFeed/2chSearch.pm:8:use Plagger::Util qw( decode_content ); lib/Plagger/Plugin/CustomFeed/2chSearch.pm:43: my $content = decode_content($res); lib/Plagger/Plugin/CustomFeed/BloglinesCitations.pm:7:use Plagger::Util qw( decode_content ); lib/Plagger/Plugin/CustomFeed/BloglinesCitations.pm:42: my $content = decode_content($res); lib/Plagger/Plugin/CustomFeed/GoogleNews.pm:49: my $content = Plagger::Util::decode_content($res); ...
--pager
好ããªãã¼ã¸ã£ãæå®ã§ãã
ex)
ack decode_content --pager="less"
.ackrcãã¡ã¤ã«
ããã$HOMEãã£ã¬ã¯ããªã«ä½ã£ã¦ããã¨ããªãã·ã§ã³ãèªåã§ä»ä¸ãã¦ãããã
(ex)
--ignore-dir=tmp --sort-files --pager=less --nogroup --type-add=ruby=.rake,rakefile,Rakefile,.builder --type-set=tags=tags
2010/4/18追è¨ããã¤ãã使ã£ãä¸ä¾
(ex)ã«ã¬ã³ããã£ã¬ã¯ããªä»¥ä¸ã®perlãã¡ã¤ã«ã®å ¨ã¦ã«å¯¾ãããthisãããthatãã«ä¸æ¬ç½®æãã
ack -f --perl | xargs perl -p -i -e's/this/that/g'
(ex)ã«ã¬ã³ããã£ã¬ã¯ããªä»¥ä¸ã®ãHogeãã«ããããããã¡ã¤ã«ã®å ¨ã¦ã«å¯¾ãããHogeãããFugaãã«ä¸æ¬ç½®æãã
ack Hoge -l | xargs perl -pi -e 's/Hoge/Fuga/g'
ããã¥ã¡ã³ã
ããã§ç´¹ä»ãããã®ã¯ããä¸é¨ã§ãã®ã§ã
ãã詳ãã使ãæ¹ãç¥ãããæ¹ã¯å
¬å¼ããã¥ã¡ã³ãããåç
§ä¸ããã
http://betterthangrep.com/
http://search.cpan.org/dist/ack/ack-base
*1:ãã®æ¤ç´¢çµæããã¼ã¹ã¨ãã¦ãä»ãªãã·ã§ã³ã®å®è¡çµæã¨è¦æ¯ã¹ã¦ã¿ã¦ä¸ãã
*2:ä½ãããªãã¦ã .svn ãblib ãªã©ã®ãã£ã¬ã¯ããªã¯èªåã§é¤å¤
*3:ã¨ããããã®ãªãã·ã§ã³ãæå¹ãªæã¯ãã¿ã¼ã³æå®ã§ããªã
*4:ããããã©ã«ãï¼