<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Pierre-Yves Aillet</title>
    <description>The latest articles on Forem by Pierre-Yves Aillet (@pyaillet).</description>
    <link>https://forem.com/pyaillet</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F376939%2F4bf2f5b6-11f7-41b0-b92d-941bf6808af0.jpeg</url>
      <title>Forem: Pierre-Yves Aillet</title>
      <link>https://forem.com/pyaillet</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pyaillet"/>
    <language>en</language>
    <item>
      <title>Agnostic livereload with Entr</title>
      <dc:creator>Pierre-Yves Aillet</dc:creator>
      <pubDate>Sun, 05 Jul 2020 08:17:40 +0000</pubDate>
      <link>https://forem.com/zenika/agnostic-livereload-with-entr-14l4</link>
      <guid>https://forem.com/zenika/agnostic-livereload-with-entr-14l4</guid>
      <description>&lt;h3&gt;
  
  
  Entr overview
&lt;/h3&gt;

&lt;p&gt;Today, I would like to introduce you to the project &lt;a href="http://eradman.com/entrproject/"&gt;entr&lt;/a&gt;.&lt;br&gt;
I discovered this project randomly a while ago, but I had been searching for a tool&lt;br&gt;
like this for a while.&lt;/p&gt;

&lt;p&gt;The goal of this tool is to provide a simple command which can launch&lt;br&gt;
a specified command when some files are modified.&lt;br&gt;
Concretely, this tool can be useful if you are searching for an alternative to&lt;br&gt;
livereload, but not related to a specific language and not related to a full&lt;br&gt;
blown &lt;a href="https://en.wikipedia.org/wiki/Integrated_development_environment"&gt;IDE&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;I often use it to automatically launch tests for &lt;a href="https://golang.org/"&gt;Golang&lt;/a&gt; projects I am&lt;br&gt;
developping.&lt;/p&gt;

&lt;p&gt;Imagine, I wish to test the following function in the&lt;br&gt;
&lt;a href="///post/entr/pkg.go"&gt;&lt;code&gt;pkg.go&lt;/code&gt;&lt;/a&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Inc returns the op1 integer incremented by one unit&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Inc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;op1&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;op1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I wish to test it, with this test in &lt;a href="///post/entr/pkg_test.go"&gt;&lt;code&gt;pkg_test.go&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Test_Inc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;testing&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;actual&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;Inc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;actual&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Errorf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Expecting: &amp;lt;2&amp;gt;, got &amp;lt;%d&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;actual&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I would launch my tests continuously with the following command:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find &lt;span class="k"&gt;*&lt;/span&gt;.go | entr &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="s2"&gt;"go test ."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here is a live preview of the result (using asciinema):&lt;/p&gt;


&lt;div class="ltag_asciinema"&gt;
  
&lt;/div&gt;



&lt;p&gt;At first, the test is not working, but as soon as the test file is updated, the&lt;br&gt;
test is launched again.&lt;br&gt;
The specificity here, is to use the &lt;code&gt;-c&lt;/code&gt; flag, in order to clear the screen&lt;br&gt;
before launching the new command.&lt;/p&gt;

&lt;p&gt;You can find the full list of options &lt;a href="http://eradman.com/entrproject/entr.1.html"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  How does it work ?
&lt;/h3&gt;

&lt;p&gt;In order to avoid &lt;a href="https://en.wikipedia.org/wiki/Polling_(computer_science)"&gt;polling&lt;/a&gt;,&lt;br&gt;
&lt;code&gt;entr&lt;/code&gt; uses file system events&lt;br&gt;
(&lt;a href="http://man.openbsd.org/kqueue.2"&gt;kqueue&lt;/a&gt; with BSD,&lt;br&gt;
&lt;a href="http://man.he.net/?section=all&amp;amp;topic=inotify"&gt;inotify&lt;/a&gt; with Linux).&lt;/p&gt;

&lt;p&gt;The full source code is available here: &lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--566lAguM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/eradman"&gt;
        eradman
      &lt;/a&gt; / &lt;a href="https://github.com/eradman/entr"&gt;
        entr
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Run arbitrary commands when files change
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;h3&gt;
  
  
  How to get it ?
&lt;/h3&gt;

&lt;p&gt;If you wish to install it, it's really easy, just use your Linux distribution package:&lt;/p&gt;

&lt;p&gt;Ubuntu, Debian, Mint, ... :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ apt install entr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Centos, ... :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ yum install entr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MacOS :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew install entr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>tool</category>
      <category>cli</category>
      <category>livereload</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
