Created
August 7, 2021 10:52
-
-
Save tdnguyen6/0fc018326f33c29e819be7f388360a5b to your computer and use it in GitHub Desktop.
Bash script to clean abandoned pipenv environments (non-existing project folder)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # get all pipenv environments | |
| allPipenvEnv=$(find ~/.local/share/virtualenvs/*/.project -type f) | |
| # find abandoned environments | |
| abandonedEnv=() | |
| for f in $allPipenvEnv; do | |
| proj_path="$(cat $f)" && [ ! -d $proj_path ] && abandonedEnv+=($proj_path) | |
| done | |
| # if there is any abandoned environment, prompt for cleaning, else, exit | |
| if [ ${#abandonedEnv[@]} -eq 0 ]; then | |
| echo "No abandoned environment, hooray" | |
| else | |
| echo "Found ${#abandonedEnv[@]} abandoned pipenv environment(s):" | |
| for value in "${abandonedEnv[@]}"; do | |
| echo $value | |
| done | |
| echo -e "\nClean up abandoned pipenv environments?" | |
| select choice in "Yes" "No"; do | |
| case $choice in | |
| Yes) | |
| for f in $allPipenvEnv; do | |
| proj_path="$(cat $f)" && [ ! -d $proj_path ] && rm -rif ${f//\/.project/} && echo DELETING ${f//\/.project/} | |
| done | |
| echo "Done!" | |
| break | |
| ;; | |
| No) | |
| break | |
| ;; | |
| esac | |
| done | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment