Skip to content

Instantly share code, notes, and snippets.

@alastori
Created November 11, 2025 20:21
Show Gist options
  • Select an option

  • Save alastori/6a43ec4d876029cb30aee808a0b93768 to your computer and use it in GitHub Desktop.

Select an option

Save alastori/6a43ec4d876029cb30aee808a0b93768 to your computer and use it in GitHub Desktop.
Script to relocate venvs from ~/Sandbox into ~/.venvs and leave symlinks
#!/usr/bin/env bash
set -euo pipefail
VENV_ROOT="${VENV_ROOT:-$HOME/.venvs}"
mkdir -p "$VENV_ROOT"
echo "Scanning $HOME/Sandbox for virtualenv activate scripts..."
processed=0
migrated=0
skipped=0
while IFS= read -r -d '' activate_path; do
env_path="$(dirname "$activate_path")"
env_dir="$(cd "$env_path/.." && pwd)"
base_env_dir="$(basename "$env_dir")"
target="$VENV_ROOT/$base_env_dir"
((processed++))
echo " • found env at $env_dir"
if [[ -L "$env_dir" ]]; then
echo " - already symlink, skipping"
((skipped++))
continue
fi
if [[ -e "$target" ]]; then
echo " - target exists ($target), skipping"
((skipped++))
continue
fi
mv "$env_dir" "$target"
ln -sfn "$target" "$env_dir"
echo " - migrated -> $target"
((migrated++))
done < <(find -L "$HOME/Sandbox" -type f -path '*/bin/activate' -print0)
echo "Done. processed=$processed migrated=$migrated skipped=$skipped"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment