dotfiles/home/private_dot_config/zsh/functions/scratch

25 lines
610 B
Text
Raw Normal View History

2025-02-11 11:19:38 -06:00
#!/usr/bin/env zsh
##? drop into a directory in ~/scratch/%Y/%U
# inspo: https://leahneukirchen.org/blog/archive/2006/01/keeping-your-home-clean-with-mess.html
2025-02-11 15:11:40 -06:00
local dir date_scratch
date_scratch=$HOME/scratch/$(date +"%Y/%U")
mkdir -p $date_scratch
ln -sfn $date_scratch $HOME/scratch/current
# cleanup any empty directories while I'm here
find $HOME/scratch/$(date +"%Y") \
-mindepth 2 -maxdepth 2 -type d -empty -print0 |\
xargs -0 --no-run-if-empty rmdir --verbose
2025-02-11 11:19:38 -06:00
if [[ -n $1 ]]; then
2025-02-11 15:11:40 -06:00
dir=$date_scratch/$1
mkdir -p $dir
2025-02-11 11:19:38 -06:00
else
2025-02-11 15:11:40 -06:00
dir=$(mktemp -d $date_scratch/$(date +"%d").XXXX)
2025-02-11 11:19:38 -06:00
fi
2025-02-11 15:11:40 -06:00
pushd $dir