Search code examples
windowsanacondaaliaswindows-terminal

Setting up alias into Anaconda prompt inside Windows Terminal


Running anaconda inside windows terminal always points me into (base) C:\WINDOWS\system32> and then I have to navigate tru directories to my target dir.

How can I add aliases into anaconda prompt inside windows terminal?


Solution

  • Inside the little arrow in Win Terminal is a Settings button. There you can open settings.json - inside this file you probably run your anaconda with command like:

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

    then if you open activate.bat file, you can add DOSKEYs.

    Example:

    @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 is just the command for clearing after.