首页 > 解决方案 > 在 Windows 终端中将别名设置为 Anaconda 提示符

问题描述

在 Windows 终端内运行 anaconda 总是将我指向(base) C:\WINDOWS\system32>,然后我必须将 tru 目录导航到我的目标目录。

如何在 Windows 终端内的 anaconda 提示符中添加别名?

标签: windowsanacondaaliaswindows-terminal

解决方案


在 Win Terminal 的小箭头里面是一个Settings按钮。在那里你可以打开settings.json- 在这个文件中你可能使用如下命令运行你的 anaconda:

"commandline": "cmd.exe /K C:\\Users\\Home\\anaconda3\\Scripts\\activate.bat"

然后如果你打开activate.bat文件,你可以添加DOSKEYs.

例子:

@REM Copyright (C) 2012 Anaconda, Inc
@REM SPDX-License-Identifier: BSD-3-Clause
@REM Test first character and last character of %1 to see if first character is a "
@REM   but the last character isn't.
@REM This was a bug as described in https://github.com/ContinuumIO/menuinst/issues/60
@REM When Anaconda Prompt has the form
@REM   %windir%\system32\cmd.exe "/K" "C:\Users\builder\Miniconda3\Scripts\activate.bat" "C:\Users\builder\Miniconda3"
@REM Rather than the correct
@REM    %windir%\system32\cmd.exe /K ""C:\Users\builder\Miniconda3\Scripts\activate.bat" "C:\Users\builder\Miniconda3""
@REM this solution taken from https://stackoverflow.com/a/31359867
@set "_args1=%1"
@set _args1_first=%_args1:~0,1%
@set _args1_last=%_args1:~-1%
@set _args1_first=%_args1_first:"=+%
@set _args1_last=%_args1_last:"=+%
@set _args1=

@REM Here you can add your aliases
doskey cdp=cd C:\Users\Home\Desktop\Porn
doskey cdg=cd C:\Users\Home\Documents\GitHub\
cls

@if "%_args1_first%"=="+" if NOT "%_args1_last%"=="+" (
    @CALL "%~dp0..\condabin\conda.bat" activate
    @GOTO :End
)

@REM This may work if there are spaces in anything in %*
@CALL "%~dp0..\condabin\conda.bat" activate %*

:End
@set _args1_first=
@set _args1_last=

cls只是之后清除的命令。


推荐阅读