<?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: Eric Bartholemy</title>
    <description>The latest articles on DEV Community by Eric Bartholemy (@thnukid).</description>
    <link>https://dev.to/thnukid</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%2F191820%2F73dd5e10-a9a9-4620-b134-f814cd871c4a.jpeg</url>
      <title>DEV Community: Eric Bartholemy</title>
      <link>https://dev.to/thnukid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thnukid"/>
    <language>en</language>
    <item>
      <title>How to manage dotfiles with GNU Stow</title>
      <dc:creator>Eric Bartholemy</dc:creator>
      <pubDate>Mon, 17 Jun 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/kabisasoftware/how-to-manage-dotfiles-with-gnu-stow-10kd</link>
      <guid>https://dev.to/kabisasoftware/how-to-manage-dotfiles-with-gnu-stow-10kd</guid>
      <description>&lt;p&gt;Dotfiles are text files that live in your &lt;code&gt;$HOME&lt;/code&gt; directory and help to configure your terminal and programs. When you are moving to a new computer, having dotfiles in a git repository makes copying these configurations a breeze.&lt;/p&gt;

&lt;p&gt;There are quite &lt;a href="https://github.com/search?q=dotfile+manager"&gt;a lot dotfile managers written&lt;/a&gt; in various languages. Basically these dotfile managers create symlinks to the dotfiles in the home directory. &lt;/p&gt;

&lt;p&gt;But do we really need a dotfile "manager" to symlink some files?&lt;/p&gt;

&lt;h2&gt;
  
  
  Meet GNU Stow 🔨
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.gnu.org/software/stow/"&gt;GNU Stow&lt;/a&gt; is a symlink farm manager, that makes packages of software appear in different locations on the filesystem.&lt;/p&gt;

&lt;p&gt;We can install the software with &lt;a href="https://brew.sh/"&gt;brew&lt;/a&gt;:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ brew install stow
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Making yourself at home 🏠
&lt;/h2&gt;

&lt;p&gt;Let's create a repository &lt;code&gt;dotfiles&lt;/code&gt; and create our first dotfile that will be linked to the home directory.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir ~/dotfiles
$ cd ~/dotfiles
$ git init .
$ echo "A simple dotfile configuration." &amp;gt; .mydotfile
$ git add .mydotfile
$ git commit -m "Create dotfiles repository"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now we have a repository, you can easily transfer. Next we need to symlink mydotfile into the home directory.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd ~
$ ln -s ~/dotfiles/mydotfile .mydotfile
$ ls -la | grep mydotfile
lrwxr-xr-x    1 e  ff      20B 29 May 11:11 .mydotfile -&amp;gt; dotfiles/.mydotfile
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now we have symlinked the dotfile in the repository to our home directory. The symlink, which is a reference to the original file, can be edited and viewed. However when you delete the symlink, the original file remains as is.&lt;/p&gt;

&lt;p&gt;We can automate the process of manually symlinking the files with Stow. As an example, let's create the following structure to setup neovim configuration files:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ tree -a ~/dotfiles
.
└── neovim
        └── .config/nvim
        └── .init.vim
    └── .vimrc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;With Stow you can link those files by simply running one command.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd ~/dotfiles
$ stow neovim
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;When we look in our home directory we see the following.&lt;/p&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls -la ~ | grep vimrc&lt;br&gt;
lrwxr-xr-x     1 e  ff    22B May 29 11:12 .vimrc -&amp;gt;  dotfiles/neovim/.vimrc

&lt;p&gt;$ ls -la ~/.config/nvim/&lt;br&gt;
lrwxr-xr-x   1 e  ff    43B May 29 11:36 init.vim -&amp;gt; ../../dotfiles/neovim/.config/nvim/init.vim&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Let's reflect on what happened 📝&lt;br&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We ran stow with our &lt;code&gt;neovim&lt;/code&gt; dotfiles directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stow finds the &lt;code&gt;.vimrc&lt;/code&gt; and the subdirectory &lt;code&gt;.config/nvim/&lt;/code&gt; with an &lt;code&gt;.init.vim&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stow creates a symbolic link one directory above the current location and also creates the structure in the home directory for &lt;code&gt;~/.config/nvim/&lt;/code&gt; and symlinks &lt;code&gt;.init.vim&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Stow makes an assumption that you want to symlink the files one directory above the directory where you have executed the stow command. Having the git repository in &lt;code&gt;~/dotfiles&lt;/code&gt; makes stow create the correct symlinks for us, in the &lt;code&gt;$HOME&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;In case you want to remove the symlink, you can type &lt;code&gt;stow -D neovim&lt;/code&gt;, which will unlink the files. Stow will warn you in case you are about to overwrite existing directories or files.&lt;/p&gt;

&lt;p&gt;I am using the described technique to symlink &lt;a href="https://github.com/thnukid/dotfiles"&gt;my own dotfiles&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>dotfiles</category>
      <category>gnustow</category>
    </item>
  </channel>
</rss>
