<?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>DEV Community: leslie burugu</title>
    <description>The latest articles on DEV Community by leslie burugu (@leslie).</description>
    <link>https://dev.to/leslie</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%2F3335%2F12947851.jpeg</url>
      <title>DEV Community: leslie burugu</title>
      <link>https://dev.to/leslie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/leslie"/>
    <language>en</language>
    <item>
      <title>CDPATH + GOPATH</title>
      <dc:creator>leslie burugu</dc:creator>
      <pubDate>Sat, 30 Dec 2017 00:00:00 +0000</pubDate>
      <link>https://dev.to/leslie/cdpath--gopath-1l66</link>
      <guid>https://dev.to/leslie/cdpath--gopath-1l66</guid>
      <description>&lt;h1&gt;
  
  
  CDPATH + GOPATH
&lt;/h1&gt;

&lt;p&gt;If you’ve ever used &lt;a href="http://golang.org"&gt;Go&lt;/a&gt; I’m pretty sure you have heard of the term &lt;strong&gt;GOPATH&lt;/strong&gt;. It refers to the internal directory structure that the Go toolchain uses to find source code and packages.&lt;/p&gt;

&lt;p&gt;If i have a project called &lt;strong&gt;weather&lt;/strong&gt; and i wanted to &lt;code&gt;cd&lt;/code&gt; into it, i would have to do something like this (assuming my &lt;strong&gt;$GOPATH&lt;/strong&gt; is set to &lt;strong&gt;$HOME/go&lt;/strong&gt; ).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd $HOME/go/src/github.com/burugux/weather/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works fine but if &lt;strong&gt;weather&lt;/strong&gt; is a directory you visit frequently typing all that becomes boring,super repetitive and also a little bit annoying.&lt;/p&gt;

&lt;p&gt;But wouldn’t it be cool if we could just &lt;strong&gt;cd weather&lt;/strong&gt; and we would be able to jump to that directory directly?&lt;/p&gt;

&lt;h3&gt;
  
  
  Introdcuing CDPATH
&lt;/h3&gt;

&lt;p&gt;It turns out we can actually do that with the help of &lt;strong&gt;CDPATH&lt;/strong&gt;. &lt;a href="http://shop.oreilly.com/product/9780596009656.do"&gt;Learning the bash shell, 3rd eidition&lt;/a&gt; defines CDPATH as&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The variable whose value, like that of &lt;strong&gt;PATH&lt;/strong&gt; , is a list of directories separated by colons. Its purpose is to augment the functionality of the cd built-in command.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By default &lt;strong&gt;CDPATH&lt;/strong&gt; is not set. To set it up so that we can jump to our Go projects faster we would do something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export CDPATH=$HOME/go/src/github.com/$USER/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So what does the above command do? Well it assigns a single value to the &lt;strong&gt;CDPATH&lt;/strong&gt; variable which is the location we would like &lt;code&gt;cd&lt;/code&gt; to use while looking for the directory we are interested in. With that exported if we typed &lt;strong&gt;cd weather&lt;/strong&gt; we would automatically go to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$HOME/go/src/github.com/$USER/weather
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How cool right?😃&lt;/p&gt;

&lt;p&gt;However please note that&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The above would only work if your github username and &lt;strong&gt;$USER&lt;/strong&gt; are the same. If not, all you have to do is replace &lt;strong&gt;$USER&lt;/strong&gt; with your actually github username.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To make it persitent add the export statement to your &lt;strong&gt;.bashrc&lt;/strong&gt; or &lt;strong&gt;.zshrc&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding more options
&lt;/h3&gt;

&lt;p&gt;Let’s imagine a scenerio where you have multiple projects in your &lt;strong&gt;GOPATH&lt;/strong&gt; which you contribute to and some of them are not under your github username as is usually the case. Using what we have learnt above is it still be possible to jump to those projects quickly without typing the entire path? Yes.&lt;/p&gt;

&lt;p&gt;To do that we would pass a second value to &lt;strong&gt;CDPATH&lt;/strong&gt; separated by a colon. For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export CDPATH=$HOME/go/src/github.com/burugux:$HOME/go/src/github.com/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that out of the way we would be able to do something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd jessfraz/weather
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And automatically go to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$HOME/go/src/github.com/jessfraz/weather
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neat! 😁&lt;/p&gt;

&lt;p&gt;If we had projects from github and gitlab can we still use &lt;strong&gt;CDPATH&lt;/strong&gt;? Again yes. All we have to do is pass a third value to &lt;code&gt;CDPATH&lt;/code&gt; and it would look something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export CDPATH=$HOME/go/src/github.com/burugux:$HOME/go/src/github.com:$HOME/go/src/gitlab.com/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that i can now do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd leslie/cool-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and automatically go to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$HOME/go/src/gitlab.com/leslie/cool-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  One caveat to note
&lt;/h3&gt;

&lt;p&gt;If i had a directory &lt;strong&gt;$HOME/weather&lt;/strong&gt; and i typed &lt;strong&gt;cd weather&lt;/strong&gt; while i was at &lt;strong&gt;$HOME&lt;/strong&gt; where would it take me?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./weather
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$HOME/go/src/github.com/burugux/weather
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;./weather&lt;/code&gt; unfourtanely. From &lt;a href="http://www.softpanorama.org/Scripting/Shellorama/cdpath.shtml"&gt;softparanoma&lt;/a&gt;, If you put a trailing slash “/” on each path in &lt;code&gt;$CDPATH&lt;/code&gt;, you’ll “cd” to the local directory. If you don’t put a trailing slash on each pathname, you’ll “cd” to the first pathname in the &lt;code&gt;$CDPATH&lt;/code&gt; list that contains a matching subdirectory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To &lt;code&gt;cd&lt;/code&gt; into the local directory i would have to do &lt;code&gt;cd ./weather&lt;/code&gt; but from anywhere else i would still be able to do &lt;code&gt;cd weather&lt;/code&gt; and go to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$HOME/go/src/github.com/burugux/weather
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope you have learnt something new and are going to use &lt;code&gt;CDPATH&lt;/code&gt; to make your life easier while using the terminal.&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Hi, I'm Leslie</title>
      <dc:creator>leslie burugu</dc:creator>
      <pubDate>Sun, 19 Feb 2017 10:51:05 +0000</pubDate>
      <link>https://dev.to/leslie/hi-im-leslie</link>
      <guid>https://dev.to/leslie/hi-im-leslie</guid>
      <description>&lt;p&gt;I have been coding for [3] years.&lt;/p&gt;

&lt;p&gt;You can find me on GitHub as &lt;a href="https://github.com/Burugux" rel="noopener noreferrer"&gt;Burugux&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in [Nairobi].&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: [C,golang].&lt;/p&gt;

&lt;p&gt;I am currently learning more about [computer science].&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
