logo一言堂

Home directory shakeup

My Homedir is a mess. It contains all sorts of files in all kinds of places; it takes a long time to find a file I want, and I don't know if I have it or not. One of my drives in 2019 is to tidy up my life, so Homedir is one of the things I need to tackle. Here is the plan I make up. Let's see if I can stick to it at the end.

Definitions

First thing first, let defines a few terms I will use throughout the document.

universe

That's my Homedir.

Atom

An atom is either a file or a directory. It should be:

  • unique. there should be only one copy of any atom in the universe.
  • self-contained. It should not contain symlinks or hard links to anything outside the Atom for one. Also, the content should not contain references to arbitrary paths outside the Atom. A shabang is ok because it is generally true to have the bash or perl in designated locations, but a href to a random path is not ok.

By ensuring uniqueness and self-contained, the Atom can be position-independent. To make sure I can place it anywhere I want, I named them uniquely. For a document, the name should be informative. In the case that there are too many Atoms of one particular type, such as the pictures I took, and it is impossible to name them one by one, the name can be auto-generated.

For auto-generated names, the names should reflect the content of the file, such as the md5 checksum. Such atoms must also be immutable. Autoincrement naming scheme, such as the convention used by digital cameras these days, is not robust because name clash can happen if you move files around.

package

A package is a collection of related atoms in a directory hierarchy. Those of the same type must conform to the same directory hierarchy rules so that one can merge them. Thanks to the unique names of all the atoms, the merge will not cause any name conflict.

project

A project a collective work that requires human involvement. A project may contain different kinds of files:

  • computer-generated that need post-processing
  • human-written files that also need post-processing
  • humen-written with no post-processing needed

The post-processing is also called building. The result of building one project is one or more packages. In the case that no building is needed, the project is also a package itself. For the project that mainly consisted of human-written files, we shall use a source control system such as git.

artifact

An artifact is a computer-generated file or a directory that needs no post-processing — for example, browser caches or downloaded random files.

Artifacts could be turned into or adopted by a project if human involvement emerged at a later time.

Atoms are stored in the package but symlinked from the outside, in the universe. This process is called stowing, and the tool itself is also called stow. Outside usually only accessed them by the links.

directory organization

The universe contains stowage links, packages, projects, and artifacts.

projects

All projects reside in the directory called "projects". The "projects" directory may contain sub-directory for further organization. All works should stay inside the "projects" directory. All files under a project are private to that project.

packages

There is a "packages" directory that is flat and contains all packages built from the projects. In the case of a project that does not need building, I symlink it into the "packages" directory. In all other circumstances, the build script should copy the built products into its package. All packages must have a unique and meaningful name.

artifacts

All regular files that are outside the "projects" or packages directory are artifacts. At the beginning of this re-org, pretty much everything is. The goal of this re-org is to minimize the amount of them by turning them into stowage links, either by forming new projects or adoption into existing projects.

On the other hand, symlinks made by stow into the packages directory are stowage links. In the beginning, there are none, but more stowage links will replace artifact as the re-org is going on. The directory organization should resemble Linux FHS with Homedir convention:

  • bin/ for all executables
  • lib/ for all libraries
  • include/ for all header files
  • share/ for all architecture-independent files
  • public_html/ for all files accessible with HTTP
  • Documents/ for all productivity suite files
  • dot files, directly on Homedir

Conclusion

You keep your wardrobe organized and your house clean. In a sense, your Homedir is just another home, probably even more critical. There is no reason not to keep it clean and organized. All it takes are careful planning and strict discipline.