diff --git a/.rc.func.sh b/.rc.func.sh index cc01c7d..bc36490 100644 --- a/.rc.func.sh +++ b/.rc.func.sh @@ -67,3 +67,34 @@ function goenv() { go env -w GOPROXY=https://goproxy.cn,direct go env -w GOPRIVATE=golang.wrdtech.com } + +function switchpy() { + local pythonlib_dir="$HOME/.local/share/pythonlib" + local python_link="$HOME/.local/share/python" + + if [ ! -d "$pythonlib_dir" ]; then + echo "Python库文件夹不存在: $pythonlib_dir" + return 1 + fi + + local python_versions=($(ls -d "$pythonlib_dir"/*/ | xargs -n 1 basename)) + + if [ ${#python_versions[@]} -eq 0 ]; then + echo "没有找到Python版本" + return 1 + fi + + echo "请选择一个Python版本:" + select version in "${python_versions[@]}"; do + if [ -n "$version" ]; then + if [ -e "$python_link" ]; then + rm "$python_link" + fi + ln -s "$pythonlib_dir/$version" "$python_link" + echo "Python已切换到版本: $version" + break + else + echo "无效的选择" + fi + done +} diff --git a/.zshrc b/.zshrc index c06607b..c8a2729 100644 --- a/.zshrc +++ b/.zshrc @@ -13,3 +13,4 @@ plugins=( source ~/.keychain.sh source ~/.rc.sh source $ZSH/oh-my-zsh.sh +source /usr/share/nvm/init-nvm.sh