her.esy.fun/src/Scratch/fr/blog/02_ackgrep/index.html

111 lines
7.4 KiB
HTML
Raw Normal View History

2021-04-18 10:23:24 +00:00
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>YBlog - Mieux que grep</title>
<link rel="shortcut icon" type="image/x-icon" href="../../../../Scratch/img/favicon.ico" />
2022-10-26 09:38:50 +00:00
<link rel="stylesheet" type="text/css" href="../../../../css/y.css" />
2021-05-25 20:25:47 +00:00
<link rel="stylesheet" type="text/css" href="/css/legacy.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" />
2021-04-18 10:23:24 +00:00
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon" href="../../../../Scratch/img/about/FlatAvatar@2x.png" />
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->
<!-- IndieAuth -->
<link href="https://twitter.com/yogsototh" rel="me">
<link href="https://github.com/yogsototh" rel="me">
<link href="mailto:yann.esposito@gmail.com" rel="me">
<link rel="pgpkey" href="../../../../pubkey.txt">
</head>
<body lang="fr" class="article">
<div id="content">
<div id="header">
<div id="choix">
<span id="choixlang">
<a href="../../../../Scratch/en/blog/02_ackgrep/">Anglais</a>
</span>
<span class="tomenu"><a href="#navigation">↓ Menu ↓</a></span>
<span class="flush"></span>
</div>
</div>
<div id="titre">
<h1>Mieux que grep</h1>
</div>
<div class="flush"></div>
<div id="afterheader" class="article">
<div class="corps">
<h1 id="mise-à-jour">Mise à jour</h1>
<p>Comme <a href="http://www.theworkinggeek.com">Andy Lester</a> me la fait remarqué. <a href="http://betterthangrep.com"><code>ack</code></a> est un simple fichier perl quil suffit de copier dans son répertoire personnel <code>~/bin</code>. Maintenant jai <code>ack</code> sur mon serveur professionnel.</p>
<p>Il suffit daller sur <a href="http://betterthangrep.com">http://betterthangrep.com</a> pour le télécharger.</p>
<p>Sincèrement, je ne comprend pas qu<code>ack</code> ne soit pas une commande implémentée par défaut sur les systèmes UNIX. Je ne peux vraiment plus men passer, il mest devenu aussi essentiel quun <code>which</code> ou un <code>find</code>.</p>
<hr />
<h1 id="mieux-que-grep">Mieux que grep</h1>
<p>Un des mes usages principaux de <code>grep</code> est</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode zsh"><code class="sourceCode zsh"><a class="sourceLine" id="cb1-1" title="1"><span class="kw">grep</span> <span class="st">'pattern'</span> **/*<span class="kw">(.)</span></a></code></pre></div>
<p>La plupart du temps cest suffisant, mais ajouter de la coloration améliore beaucoup lutilité de cette commande. Il existe déjà un outil pour ça : il sappelle <code>ack-grep</code> sous Ubuntu. Comme je ne peux pas linstaller sur le serveur de mon entreprise, jen ai créé un moi-même en quelques lignes&nbsp;:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode zsh"><code class="sourceCode zsh"><a class="sourceLine" id="cb2-1" title="1"><span class="co">#!/usr/bin/env zsh</span></a>
<a class="sourceLine" id="cb2-2" title="2"><span class="kw">((</span><span class="ot">$#</span>&lt;1<span class="kw">))</span> <span class="kw">&amp;&amp;</span> <span class="kw">{</span> <span class="kw">print</span> <span class="st">'usage: ack &quot;regexp&quot;'</span> <span class="kw">&gt;&amp;2</span>; <span class="kw">exit</span> 1 <span class="kw">}</span></a>
<a class="sourceLine" id="cb2-3" title="3"></a>
<a class="sourceLine" id="cb2-4" title="4"><span class="ot">listeFic=(</span> **/*(.<span class="ot">)</span> )</a>
<a class="sourceLine" id="cb2-5" title="5"><span class="kw">autoload</span> zargs</a>
<a class="sourceLine" id="cb2-6" title="6">zargs -- <span class="ot">$listeFic</span> -- <span class="kw">grep</span> <span class="ot">$1</span> <span class="kw">|</span> <span class="kw">perl</span> -ne <span class="st">'use Term::ANSIColor;</span></a>
<a class="sourceLine" id="cb2-7" title="7"><span class="st">if (m/([^:]*)(:.*)('</span><span class="ot">$1</span><span class="st">')(.*)/) {</span></a>
<a class="sourceLine" id="cb2-8" title="8"><span class="st"> print color(&quot;green&quot;).$1;</span></a>
<a class="sourceLine" id="cb2-9" title="9"><span class="st"> print color(&quot;reset&quot;).$2;</span></a>
<a class="sourceLine" id="cb2-10" title="10"><span class="st"> print color(&quot;black&quot;,&quot;on_yellow&quot;).$3;</span></a>
<a class="sourceLine" id="cb2-11" title="11"><span class="st"> print color(&quot;reset&quot;).$4.&quot;\n&quot;;</span></a>
<a class="sourceLine" id="cb2-12" title="12"><span class="st">} '</span></a></code></pre></div>
<p>Pour mon utilisation personnelle et celle de mon équipe cest suffisant. Jespère que ça pourra vous aider.</p>
</div>
<div id="afterarticle">
<div id="social">
2021-05-25 20:25:47 +00:00
<a href="/rss.xml" target="_blank" rel="noopener noreferrer nofollow" class="social">RSS</a>
2021-04-18 10:23:24 +00:00
·
<a href="https://twitter.com/home?status=http%3A%2F%2Fyannesposito.com/Scratch/fr/blog/02_ackgrep/%20via%20@yogsototh" target="_blank" rel="noopener noreferrer nofollow" class="social">Tweet</a>
·
<a href="http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fyannesposito.com/Scratch/fr/blog/02_ackgrep/" target="_blank" rel="noopener noreferrer nofollow" class="social">FB</a>
<br />
<a class="message" href="../../../../Scratch/fr/blog/Social-link-the-right-way/">Ces liens sociaux préservent votre vie privée</a>
</div>
<div id="navigation">
<a href="../../../../">Accueil</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/blog">Blog</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/softwares">Logiciels</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/about">Auteur</a>
</div>
<div id="totop"><a href="#header">↑ Top ↑</a></div>
<div id="bottom">
<div>
Published on 2009-07-22
</div>
<div>
<a href="https://twitter.com/yogsototh">Follow @yogsototh</a>
</div>
<div>
<a rel="license" href="http://creativecommons.org/licenses/by/3.0/deed.en_US">Yann Esposito©</a>
</div>
<div>
Done with
<a href="http://www.vim.org" target="_blank" rel="noopener noreferrer nofollow"><strike>Vim</strike></a>
<a href="http://spacemacs.org" target="_blank" rel="noopener noreferrer nofollow">spacemacs</a>
<span class="pala">&amp;</span>
<a href="http://nanoc.ws" target="_blank" rel="noopener noreferrer nofollow"><strike>nanoc</strike></a>
<a href="http://jaspervdj.be/hakyll" target="_blank" rel="noopener noreferrer nofollow">Hakyll</a>
</div>
2022-10-26 09:26:08 +00:00
2021-04-18 10:23:24 +00:00
</div>
</div>
</div>
</div>
</body>
</html>