The Alchemist Dev

Explorations & Rants

Do you collect rust projects from public repos?

Are you low on disk space?

If you answered yes and yes, then give this a go.

Environment

All of my cloned rust projects are in a single location (60.02 rust) organized with the Johnny Decimal system.

Example

# $HOME
60s IT Library
└ 60 clones
  └ 60.02 rust
    ├ clean.sh
    ├ bevy/
    ├ cosmic-text/
    ├ Fyrox/
    ├ ... # clipped for brevity
    ├ wgpu/
    ├ winit/
    └ zola/

The Script

clean.sh contains the following.

#!/bin/bash

# collect the list of directories
DIR_LIST=($(ls -d */))

# print the directory statistics with a depth of 0
ds -d 0

# for each directory ...
for D in "${DIR_LIST[@]}"; do
  # enter it ...
  cd "$D"
  # and if target/ exists ...
  if [ -d "target" ]; then
    echo cleaning "$D"
    # remove it
    rm -R target
  fi
  # exit it ...
  cd ../
done
# print the directory statistics again
ds -d 0

ds is dirstat-rs: A disk usage cli similar to windirstat.

Output

user@host ~ % cdj 60.02 # change directory Johnny!
user@host 60.02 rust % ./clean.sh

Analysing: $HOME/60s IT library/60 clones/60.02 rust

└── 100.00% [67.1 GB] ── 60.02 rust
cleaning bevy/
cleaning cosmic-text/
cleaning Fyrox/
... # clipped for brevity
cleaning wgpu/
cleaning winit/
cleaning zola/

Analysing: $HOME/60s IT library/60 clones/60.02 rust

└── 100.00% [3.46 GB] ── 60.02 rust
user@host 60.02 rust %

Yup. I saved 64GB of space.

cdj is just a quick line in zshrc. It errors if the directory number doesn't exist or if there are duplicate entries.

# in .zshrc
export cdj(){
  cd $HOME/*/*/${1}*
}

Have fun with this.