Merge pull request #194 from Mejituu/master
Fixed the problem of randomly generating garbage in each directory when entering the working directory subdirectory, and cleaning the garbage during rmvenv
Diff
1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
2index da176cc23c70d52c9d3746e64d7b56025d007a12..7f64ff8626e1eff0ae50f31e01be0999d9d0b958 100644
3--- a/autoswitch_virtualenv.plugin.zsh
4+++ b/autoswitch_virtualenv.plugin.zsh
5@@ -7,6 +7,8 @@ AUTOSWITCH_PURPLE="\e[35m"
6 AUTOSWITCH_BOLD="\e[1m"
7 AUTOSWITCH_NORMAL="\e[0m"
8 9+VIRTUAL_ENV_DIR="${AUTOSWITCH_VIRTUAL_ENV_DIR:-$HOME/.virtualenvs}"
10+
11 function _validated_source() {
12 local target_path="$1"
1314@@ -23,8 +25,6 @@ function _validated_source() {
1516 function _virtual_env_dir() {
17 local venv_name="$1"
18- local VIRTUAL_ENV_DIR="${AUTOSWITCH_VIRTUAL_ENV_DIR:-$HOME/.virtualenvs}"
19- mkdir -p "$VIRTUAL_ENV_DIR"
20 printf "%s/%s" "$VIRTUAL_ENV_DIR" "$venv_name"
21 }
2223@@ -264,6 +264,9 @@ function rmvenv()
24 # https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s04.html
25 # https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/
26 /bin/rm -rf "$(_virtual_env_dir "$venv_name")"
27+ if [[ -z "$(/bin/ls -A $VIRTUAL_ENV_DIR)" ]]; then
28+ /bin/rm -rf "$VIRTUAL_ENV_DIR"
29+ fi
30 /bin/rm "$AUTOSWITCH_FILE"
31 else
32 printf "No $AUTOSWITCH_FILE file in the current directory!\n"
33@@ -337,6 +340,8 @@ function mkvenv()
34 params+="--python=$AUTOSWITCH_DEFAULT_PYTHON"
35 fi
3637+ /bin/mkdir -p "$VIRTUAL_ENV_DIR"
38+
39 if [[ ${params[(I)--verbose]} -eq 0 ]]; then
40 virtualenv $params "$(_virtual_env_dir "$venv_name")"
41 else