DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Managing Dotfiles With Stow

Managing Dotfiles With Stow

As a programmer, much of our time at work is spent developing code that we usually spend a lot of time configuring the toolset that we use on a daily basis.

Oscar Galindo user avatar by
Oscar Galindo
·
Nov. 29, 22 · Tutorial
Like (1)
Save
Tweet
Share
5.12K Views

Join the DZone community and get the full member experience.

Join For Free

As a programmer, much of our time at work is spent developing code (and attending meetings, of course. ), So much so that we usually spend a lot of time configuring the toolset that we use on a daily basis. We are not only talking about the evolution of the configuration but also about how to configure your new laptop, have several computers, or simply share a certain configuration of a certain tool with a colleague.

The great majority of applications (and more in UNIX systems) are configured through the well-known “dotfiles” (stored in the user’s $HOME), which are not more than files or folders that begin with a . to configure the applications (ex: .bashrc, .git/). The purpose of starting with a dot is that, by default operating systems treat them as hidden files and don’t show them unless you tell them to.

Before we start, let’s explain the three terms we need to know to work with STOW, which are: Package, Stow Directory and Target Directory.

  1. Package: It’s a collection of files that must be “installed” together in the same target directory.
  2. Stow directory: It’s the repository where all our packages will be.
  3. Target directory: It’s the directory where we want to install those configurations that are in our packages.

Package, Stow Directory and Target Directory

The functionality that we are looking for, Stow, will generate a symbolic link of the files we have inside our packages in the target directory. In the example, if we run stow git, it will create a link from ~/.gitconfig to ~/.dotfiles/git/.gitconfig.

In this case, the convention decided by the community is to place everything inside a directory called .dotfiles inside our home, but this is something that can be appreciated by reading forums and articles about dotfiles management. It has certain logic since, in stow, by default, the target directory is the parent of the stow directory. That means that if we place ~/.dotfiles as the stow directory, the target directory will be ~/, which is where we will want to place our dotfiles.

The purpose of this article is to get our git (.gitconfig) and zsh (.zshrc) configuration out of our home without any control and move it into our .dotfiles folder, where we can upload it to a git repository (stow with git has very good synergy), synchronize it with Dropbox, or whatever we like.

To begin, we are going to create our stow directory, which can be wherever we like, but in this article, we will use ~/.dotfiles for the reasons that have been previously explained. Now, we are going to start creating the git configuration. For it, we will create our git package inside our stow directory, and inside it, the configuration files related to git that we want to create a simlink in the target directory.
In this case, it will be only our .gitconfig:

 
$ cd ~
$ mkdir -p .dotfiles/git

$ touch .dotfiles/git/.gitconfig


Now what we are looking for is to copy the content of the .gitconfig with the current configuration that is in the user’s $HOME (~/.gitconfig), and paste it in the new file generated inside our stow directory.
To do this, we are going to launch the stow command with the parameters -adopt, -n, and -v, and as an argument, we will tell it that we want to stow in the git folder: stow -adopt -nv git.

 
$ stow –adopt -nv git


Let’s explain what each option does separately:

  • -n: With this option, we are telling stow not to execute any action; tell us what it intends to do if we remove the option.
  • -v: This option is the one that will allow us to read what stow intends to do (in the end, it’s to increase the verbosity level).
  • -adopt: This option is the only one that modifies the stow directory; all the others focus on the target directory. With this option, what we do is that prior to stowear, it will move the current file in the target directory to the stow directory and then create the link. Very useful when we are starting to create our .dotfiles.

Once we see the actions it will do, we just need to remove the -n option from the command to run it:

 
$ stow -adopt -v git


With this, we can see how to save the current configuration inside our .dotfiles and how stow manages all the links in an easy way.

To finish the article, I would like to comment in a summarized way on what other things I have needed to do with stow:

  • Remove the link from a configuration: stow -D (by default .is in link mode, which is -S).
  • What happens if we delete a file from our stow directory (~/.dotfiles) that was already stowed? The file does not exist, but the link is still there; for that, we have stow -R, which is basically a shortcut to stow -D && stow -S.
  • If, for some reason, you don’t want to have your dotfiles repository in the home (pe: ~/projects/dotfiles), and given that the target directory is the parent (in this case, it will be ~/projects), we must make explicit where we want to create the configuration links, for that we must use stow -t=~.
Contextual design Git IT applications Command (computing) Directory Links Programmer (hardware) Repository (version control) systems

Published at DZone with permission of Oscar Galindo. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Java Development Trends 2023
  • A Complete Guide to AngularJS Testing
  • Spring Cloud: How To Deal With Microservice Configuration (Part 1)
  • Type Variance in Java and Kotlin

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: