为了在 Windows 上使用 zsh,需要一个类 Unix 环境。推荐使用 Git Bash,您可以从官网下载并安装
2 下载 zsh下载 zsh
下载 zsh将下载的内容解压到 git 的根目录中
设置 git 使用 zsh,在.bashrc中配置
shell
if [ -t 1 ]; then exec zsh fi再次启动 git bash,光标和提示在同一行说明成功进入了 zsh
在你的$USERPROFILE下新建.zshrc作为 zsh 的启动脚本
shell
2.1 conda 设置(可选的)如果未经配置在命令行中使用 conda 可能会遇到 LF 的问题
在用户目录下新建一个 conda 初始化脚本conda-shell-zsh-hook.zsh,粘贴以下内容,将 CONDA_EX 和 CONDA_PYTHON_EXE 中的路径修改为你的 Conda 路径
shell
export PYTHONIOENCODING=UTF-8 export CONDA_EXE="$(cygpath 'D:\Workspace\Environment\python\anaconda3\Scripts\conda.exe')" export _CE_M='' export _CE_CONDA='' export CONDA_PYTHON_EXE="$(cygpath 'D:\Workspace\Environment\python\anaconda3\python.exe')" # Copyright (C) 2012 Anaconda, Inc # SPDX-License-Identifier: BSD-3-Clause __conda_exe() ( "$CONDA_EXE" $_CE_M $_CE_CONDA "$@" | tr -d '\r' ) __conda_hashr() { if [ -n "${ZSH_VERSION:+x}" ]; then \rehash elif [ -n "${POSH_VERSION:+x}" ]; then : # pass else \hash -r fi } __conda_activate() { if [ -n "${CONDA_PS1_BACKUP:+x}" ]; then # Handle transition from shell activated with conda = 4.4. See issue #6173. PS1="$CONDA_PS1_BACKUP" \unset CONDA_PS1_BACKUP fi \local ask_conda ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix "$@")" || \return \eval "$ask_conda" __conda_hashr } __conda_reactivate() { \local ask_conda ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix reactivate)" || \return \eval "$ask_conda" __conda_hashr } conda() { \local cmd="${1-__missing__}" case "$cmd" in activate | deactivate) __conda_activate "$@" ;; install | update | upgrade | remove | uninstall) __conda_exe "$@" || \return __conda_reactivate ;; *) __conda_exe "$@" ;; esac } if [ -z "${CONDA_SHLVL+x}" ]; then \export CONDA_SHLVL=0 # In dev-mode CONDA_EXE is python.exe and on Windows # it is in a different relative location to condabin. if [ -n "${_CE_CONDA:+x}" ] && [ -n "${WINDIR+x}" ]; then PATH="$(\dirname "$CONDA_EXE")/condabin${PATH:+":${PATH}"}" else PATH="$(\dirname "$(\dirname "$CONDA_EXE")")/condabin${PATH:+":${PATH}"}" fi \export PATH # We're not allowing PS1 to be unbound. It must at least be set. # However, we're not exporting it, which can cause problems when starting a second shell # via a first shell (i.e. starting zsh from bash). if [ -z "${PS1+x}" ]; then PS1= fi fi # conda activate base在.zshrc中激活此脚本
shell
# >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! if [ -f '/d/Workspace/Environment/python/anaconda3/Scripts/conda.exe' ]; then export PYTHONIOENCODING=UTF-8 source ~/conda-shell-zsh-hook.zsh fi if [ -f "/d/Workspace/Environment/python/anaconda3/etc/profile.d/mamba.sh" ]; then . "/d/Workspace/Environment/python/anaconda3/etc/profile.d/mamba.sh" fi # >> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! if [ -f '/d/Workspace/Environment/python/anaconda3/Scripts/conda.exe' ]; then export PYTHONIOENCODING=UTF-8 source ~/conda-shell-zsh-hook.zsh fi if [ -f "/d/Workspace/Environment/python/anaconda3/etc/profile.d/mamba.sh" ]; then . "/d/Workspace/Environment/python/anaconda3/etc/profile.d/mamba.sh" fi #