Do you want to keep your home directory tidy and free from clutter? If so, xdg-ninja is here to help. This shell script checks your $HOME for unwanted files and directories, and tells you if it’s possible to move them to a more appropriate location.

The configurations for xdg-ninja come from the Arch Wiki page on XDG_BASE_DIR, antidot, and other users. The script is easy to use, and you can run it either manually or with Homebrew.

If you’re using nix, you can run the following command: nix run github:b3nj5m1n/xdg-ninja.

xdg-ninja’s dependencies include your favorite POSIX-compliant shell, and jq for parsing the JSON files. Additionally, you can use optional programs like glow for rendering Markdown in the terminal.

You can configure xdg-ninja by defining a program and a list of files and directories that this program puts into your $HOME directory. For each file or directory, you can specify if it can be moved, and if so, you can provide instructions on how to accomplish that.

To learn more about xdg-ninja, visit the project’s GitHub repository. Keep your $HOME clean with xdg-ninja!

    1 year ago

    That is really cool. It is really annoying that so much software clutters $HOME with their files and directory. Worst offender is Go which does not even hide its directory.

    • How is that the worst? Offlineimap adds three different dotfiles in $HOME. OhMyZsh turns one .zshrc into two (~/.zshrc and ~/.zshrc.local). Countless programs put multiple dotfiles at the top level – go is the worse just because it doesn’t start with a dot?

      The directory is easily moved; the environment variable GOPATH declares where the tooling looks for it. Set GOPATH=~/.go in your profile or shell rc, and mv go .go. Or, if you’re cleaning up $HOME, move it to ~/.local (mv go .local/go) and set your GOPATH to that (export GOPATH=~/.local/go). Don’t forget to add $GOPATH/bin to your path, if you have executables you use.

        51 year ago

        How is that the worst? […] go is the worse just because it doesn’t start with a dot?

        Yes. Because its default location is not hidden. I can easily ignore dotfiles because they do not show up in a call to `ls’ without any flags, and because graphical file managers do not show them by default. It is just a phenomenally stupid decision by the Go project.

        Thanks for the tip anyway.

        • Rob Pike is the author of the most commonly quoted records about dotfiles, and how they were a mistake; this has indirectly led to the creation of the program under which we’re discussing.

          Pike is also one of the original creators of Go, and it would have been extremely odd if he’d have perpetuated what he’s gone on record as being one of the great mistakes of Unix. One of the original creator of Unix was another of the creators of Go, which would lend strength to the belief that those involved believe dotfiles were a regrettable, unexpected, and undesireable consequence of shortcuts.

          In short, many people believe that programs “hiding” files and directories is an antipattern, and they should put their directories out in the open, or where the user chooses them to live… jusy like Go does.

            71 year ago

            And Pike wrote this passage in the very article you mentioned:

            (For those who object that dot files serve a purpose, I don’t dispute that but counter that it’s the files that serve the purpose, not the convention for their names. They could just as easily be in $HOME/cfg or $HOME/lib, which is what we did in Plan 9, which had no dot files. Lessons can be learned.)

            And guess what, there is actually such a directory on most Unix-derived OS nowadays - $XDG_DATA_HOME/$XDG_CACHE_HOME, which Go could just honour if the environment variable was set and fallback to cluttering $HOME. But no, they insist on their insular solution…

            • I agree, I’d rather have it in .local/share/ or something like that. Not all *nix OSes use XDG (eg BSD variants), and even many linux distributions don’t use it by default. I suspect they did it for consistency as much as from a philosophy of “don’t hide things from users, they’re adults, not children.”

              If you read Pike’s argument, it’s an argument for simply putting things in $HOME, out in the open.

              I personally believe XDG has the right idea, but is a bad implementation. They should have put local, cache, and config without the dots.

              IMO, the absolute worst offenders of FS use is Electron apps, which put all app files on .config. db files, cache files, temp files… they all go in .config/APPNAME, which makes version controlling .config a lot of work. That’s far mor offensive than an app creating a single, self-contained directory for itself in $HOME.