Skip to content

spring cleaning

NNB edited this page Feb 6, 2022 · 32 revisions

Spring cleaning your $HOME

Clean as $HOME

Artwork by ใ„ใฎใตใจใ‚“

๐Ÿ’ก About

This is the ultimate test of minimalism.

After watching the video of Luke Smith's video Spring Cleaning your Home! (~/, That is...), i decided to clean up my ugly messy $HOME that have over 50 items.

Update:

  • My dotfiles have go through a lot of change and so as my home directory. My shell config nowaday doesn't even do anything to clean the home dir anymore because most of the program I use are either respect the home dir by default or just dump stuff on the home dir with no way to change it.
  • At the end of this post I show that my home dir have 0 junks, that is on mid 2021 where I use Void Linux. And to be honest, I cheated a little bit by having a script that auto delete junk from the home dir. But nowadays I still can keep my home dir under 20 items.

๐Ÿš€ Setup

๐Ÿ“ File structure

This is the file structure that we desire:

~/
โ”œโ”€ .cache/    # $XDG_CACHE_HOME
โ”œโ”€ .config/   # $XDG_CONFIG_HOME
โ”œโ”€ .local/
โ”‚  โ”œโ”€ share/  # $XDG_DATA_HOME
โ”‚  โ””โ”€ bin/    # $PATH
โ”‚
โ”œโ”€ c/         # Dotfiles ("c" stand for "config")
โ”œโ”€ d/         # Documents
โ”œโ”€ m/         # Medias (Images, videos and Musics)
โ””โ”€ t/         # Test, clone git repo, download files...

๐Ÿท๏ธ Naming

Naming common access directories shooter with no capital letter make it easier to type, you don't have to hold Shift at the start of press Tab to quickly extend it with your pinky:

Old Keypress New Keypress
Dotfiles 9 c 1
Documents 10 d 1
Images, Videos, Musics 7 m 1
Desktop, Downloads ... 8~ t 1

Yes, holding Shift is count as a keypress.

๐Ÿ—‚๏ธ XDG base directory

From XDG Base Directory Specification:

Various specifications specify files and file formats. This specification defines where these files should be looked for by defining one or more base directories relative to which files should be located.

The XDG Base Directory Specification is based on the following concepts:

  • There is a single base directory relative to which user-specific data files should be written. This directory is defined by the environment variable $XDG_DATA_HOME.
  • There is a single base directory relative to which user-specific configuration files should be written. This directory is defined by the environment variable $XDG_CONFIG_HOME.
  • There is a single base directory relative to which user-specific non-essential (cached) data should be written. This directory is defined by the environment variable $XDG_CACHE_HOME.

This method involves around export environment variables with a separate file env so the variables will be set on any shell that the system start with:

  • First set the user directories:
    export XDG_CACHE_HOME="$HOME/.cache"
    export XDG_CONFIG_HOME="$HOME/.config"
    export XDG_DATA_HOME="$HOME/.local/share"
    
    export XDG_DOCUMENTS_DIR="$HOME/d"
    export XDG_PICTURES_DIR="$HOME/i"
    export XDG_VIDEOS_DIR=XDG_PICTURES_DIR
    export XDG_MUSIC_DIR="$HOME/m"
    export XDG_DESKTOP_DIR="$HOME/t"
    export XDG_DOWNLOAD_DIR="$XDG_DESKTOP_DIR"
    export XDG_PUBLICSHARE_DIR="$XDG_DESKTOP_DIR"
    export XDG_TEMPLATES_DIR="$XDG_DESKTOP_DIR"
  • Remember to change XDG directories:
    xdg-user-dirs-update --set DOCUMENTS   "$XDG_DOCUMENTS_DIR"
    xdg-user-dirs-update --set PICTURES    "$XDG_PICTURES_DIR"
    xdg-user-dirs-update --set VIDEOS      "$XDG_VIDEOS_DIR"
    xdg-user-dirs-update --set MUSIC       "$XDG_MUSIC_DIR"
    xdg-user-dirs-update --set DESKTOP     "$XDG_DESKTOP_DIR"
    xdg-user-dirs-update --set DOWNLOAD    "$XDG_DOWNLOAD_DIR"
    xdg-user-dirs-update --set PUBLICSHARE "$XDG_PUBLICSHARE_DIR"
    xdg-user-dirs-update --set TEMPLATES   "$XDG_TEMPLATES_DIR"
  • For applications and other just take a look at this list and do as they said:
    export XINITRC="$XDG_CONFIG_HOME/X11/xinitrc"
    export XSERVERRC="$XDG_CONFIG_HOME/X11/xserverrc"
    export ICEAUTHORITY="$XDG_CACHE_HOME/ICEauthority"
    export INPUTRC="$XDG_CONFIG_HOME/readline/inputrc"
    export GNUPGHOME="$XDG_DATA_HOME/gnupg"
    export HISTFILE="$XDG_DATA_HOME/bash/history"
    export CARGO_HOME="$XDG_DATA_HOME/cargo"
    export GTK_RC_FILES="$XDG_CONFIG_HOME/gtk-1.0/gtkrc"
    export GTK2_RC_FILES="$XDG_CONFIG_HOME/gtk-2.0/gtkrc"
  • Sometimes such as git, you have to make a directory or a file in the XDG base directory to make it work:
    mkdir $HOME/.config/git && echo '' >> $HOME/.config/git/config

๐Ÿšฎ Remove junks

Final remove those junks that got left behind:

rm $HOME/.ICEauthority
rm $HOME/.bash_history
rm $HOME/.bash_logout
rm $HOME/.bash_profile
rm $HOME/.bashrc # Remove if you use other shell
rm $HOME/.inputrc
rm $HOME/.xinitrc
rm $HOME/.xsession
rm $HOME/.xsession-errors

Move everything in Desktop, Documents, Downloads, ... to t/:

mv --interactive $HOME/Documents $HOME/d
mv --interactive $HOME/Pictures  $HOME/i
mv --interactive $HOME/Videos    $HOME/i
mv --interactive $HOME/Music     $HOME/m
mv --interactive $HOME/Desktop   $HOME/t
mv --interactive $HOME/Downloads $HOME/t
mv --interactive $HOME/Public    $HOME/t
mv --interactive $HOME/Templates $HOME/t

๐ŸŽ‰ Result

This is what my $HOME directory structure look like:

~/ # 7 directories (4 used, 3 XDG, 0 junk)
โ”œโ”€ c/
โ”œโ”€ d/
โ”œโ”€ m/
โ”œโ”€ t/
โ”‚
โ”œโ”€ .cache/
โ”œโ”€ .config/
โ””โ”€ .local/

๐Ÿ’Œ Credits

Special thanks to: