aboutsummaryrefslogtreecommitdiff
path: root/build/blog/2015-12-26-autoenv-with-auto-cleanup.html
blob: 544154e4cebcdc995c4652b736e48c113d397fd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta content="pandoc" name="generator"/>
<meta content="Zhiming Wang" name="author"/>
<meta content="2015-12-26T00:15:48-08:00" name="date"/>
<title>autoenv with auto cleanup</title>
<link href="/img/apple-touch-icon-152.png" rel="apple-touch-icon-precomposed"/>
<meta content="#FFFFFF" name="msapplication-TileColor"/>
<meta content="/img/favicon-144.png" name="msapplication-TileImage"/>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<link href="/css/normalize.min.css" media="all" rel="stylesheet" type="text/css"/>
<link href="/css/theme.css" media="all" rel="stylesheet" type="text/css"/>
<link href="/css/highlight.css" media="all" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="archival-notice">This blog has been archived.<br/>Visit my home page at <a href="https://zhimingwang.org">zhimingwang.org</a>.</div>
<nav class="nav">
<a class="nav-icon" href="/" title="Home"><!--blog icon--></a>
<a class="nav-title" href="/"><!--blog title--></a>
<a class="nav-author" href="https://github.com/zmwangx" target="_blank"><!--blog author--></a>
</nav>
<article class="content">
<header class="article-header">
<h1 class="article-title">autoenv with auto cleanup</h1>
<div class="article-metadata">
<time class="article-timestamp" datetime="2015-12-26T00:15:48-08:00">December 26, 2015</time>
</div>
</header>
<p>I heard about <a href="https://github.com/kennethreitz/autoenv">kennethreitz/autoenv</a> a long time ago. The idea of autoloading project-specific environment modifications is nice, but no auto cleanup after leaving a project was a showstopper for me.</p>
<p>Today, I took matters into my own hands and wrote a fresh Zsh implementation<a class="footnoteRef" href="#fn1" id="fnref1"><sup>1</sup></a> with auto cleanup support. Check it out: <a class="uri" href="https://github.com/zmwangx/prezto/tree/master/modules/autoenv">https://github.com/zmwangx/prezto/tree/master/modules/autoenv</a>.</p>
<p>As a quick promotion, let me show you two common examples.</p>
<p>First, inserting some local bin directory into the search path. This is easily done by a one-line <code>.env</code>, say,</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh">autoenv-insert-paths bin libexec</code></pre></div>
<p>This way <code>$PWD/bin</code> and <code>$PWD/libexec</code> are inserted to the beginning of the search path, which will persist until you leave the directory tree. That is to say, the inserted paths will still be available when you descend into subdirectories (and more specific <code>.env</code>'s can even be stacked as you descend), but they will be purged as soon as you leave the tree. Clever, isn't it?</p>
<p>Secondly, exporting project-specific environment variables. The <code>.env</code> would look like</p>
<div class="sourceCode"><pre class="sourceCode zsh"><code class="sourceCode zsh"><span class="kw">export</span> <span class="ot">HOMEBREW_DEVELOPER=</span>not-for-the-faint-hearted

<span class="fu">autoenv-purge ()</span> <span class="kw">unset</span> HOMEBREW_DEVELOPER</code></pre></div>
<p>where the body of <code>autoenv-purge</code> will be executed when you leave the directory tree. No more junk floating around.</p>
<p>Again, for more info, including detailed usage and customization instructions, please visit <a href="https://github.com/zmwangx/prezto/tree/master/modules/autoenv"><code>modules/autoenv</code></a> in zmwangx/prezto.</p>
<div class="footnotes">
<hr/>
<ol>
<li id="fn1"><p>This is not a re-implementation in the common sense. My little Zsh module is inspired by kennethreitz/autoenv and reminiscent of that older project, but I took nothing from there (in fact I didn't even read their source code). I also don't claim to support their entire feature set. For instance, kennethreitz/autoenv claims to be Foreman compatible, which includes turning on <code>ALL_EXPORT</code>. However, I don't think <code>ALL_EXPORT</code> by default is a good idea, so with my <code>autoenv</code>, if you want <code>ALL_EXPORT</code> you have to set it explicitly.<a class="footnotes-backlink" href="#fnref1">↩︎</a></p></li>
</ol>
</div>
</article>
<hr class="content-separator"/>
<footer class="footer">
<span class="rfooter">
<a class="rss-icon" href="/rss.xml" target="_blank" title="RSS feed"><!--RSS feed icon--></a><a class="atom-icon" href="/atom.xml" target="_blank" title="Atom feed"><!--Atom feed icon--></a><a class="cc-icon" href="https://creativecommons.org/licenses/by/4.0/" target="_blank" title="Released under the Creative Commons Attribution 4.0 International license."><!--CC icon--></a>
<a href="https://github.com/zmwangx" target="_blank">Zhiming Wang</a>
</span>
</footer>
</body>
</html>