{%- import "utils/batch.txt" as batch -%} {%- macro cd(directory, tabs) -%} if /i not "%$p%CD%$p%"=="{{ directory }}" (^ {%- call batch::indent(tabs) %} %__builtin_cd% {{ directory|safe }}^ {%- call batch::indent(tabs) %} ^&^& set "OLDPWD=%$p%CD%$p%"^ {%- if echo -%} {%- call batch::indent(tabs) %} ^&^& {%~ call pwd(tabs + 1) -%}^ {%- endif -%} {%- if hook != InitHook::None -%} {%- call batch::indent(tabs) %} ^&^& for /f "delims=" %$p%a in ('"%__builtin_pwd%"') do @if /i not "%$p%~dpa"=="%$p%~fa" (^ {%- call batch::indent(tabs) %} zoxide add -- "%$p%~fa"^ {%- call batch::indent(tabs) %} ) else (^ {%- call batch::indent(tabs) %} zoxide add -- "%$p%~fa\"^ {%- call batch::indent(tabs) %} )^ {%- endif -%} {%- call batch::indent(tabs) %}) {%- endmacro cd -%} {%- macro pwd(tabs) -%} (^ {%- if resolve_symlinks -%} {%- call batch::indent(tabs) %} (^ {%- call batch::indent(tabs) %} for /f "skip=9 tokens=1,2,*" %$p%j in ('"%$fsutil% reparsepoint query ."') do @(^ {%- call batch::indent(tabs) %} if "%$p%~j"=="Print" if "%$p%~k"=="Name:" if not "%$p%~l"=="" (echo(%$p%~l)^ {%- call batch::indent(tabs) %} )^ {%- call batch::indent(tabs) %} ) ^|^| %__builtin_pwd%^ {%- else -%} {%- call batch::indent(tabs) %} %__builtin_pwd%^ {%- endif -%} {%- call batch::indent(tabs) %}) {%- endmacro pwd -%} {%- let section = "@rem ==========================================================================\n@rem" -%} {%- let not_configured = "@rem -- not configured --" -%} @(set ^"^") >nul 2>nul && (echo off) || ( echo zoxide: unable to init with Command Extensions disabled ^(see `help cmd` for details^) ) >&2 && exit /b 1 "Command Extensions are disabled" 2>nul setlocal DisableDelayedExpansion EnableExtensions if /i "%~f0"=="%~dpnx0" ( set ^"$p=%%^&2 ^& %$false%^ )^ ) else if "%$p%~i"=="~" (^ if defined USERPROFILE (^ {% call cd("%$p%USERPROFILE%$p%", 4) -%}^ ) else (^ (echo(%__zoxide_cd%: USERPROFILE is not defined) ^>^&2 ^& %$false%^ )^ ) else if "%$p%~i"=="-" (^ if defined OLDPWD (^ {% call cd("%$p%OLDPWD%$p%", 4) -%}^ ) else (^ (echo(%__zoxide_cd%: OLDPWD is not defined) ^>^&2 ^& %$false%^ )^ ) else (^ (^ {% call cd("%$p%~fi", 4) -%}^ )^ )^ )^ ) ^&^& %$true% @rem pwd based on the value of _ZO_RESOLVE_SYMLINKS. %$doskey% %__zoxide_pwd% = {%~ call pwd(0) %} {{ section }} @rem Commands for zoxide. Disable these using --no-cmd. @rem {%- match cmd %} {%- when Some with (cmd) %} set __zoxide_command={{cmd}} @rem Jump to a directory using only keywords. %$doskey% %__zoxide_command% = (^ {% call batch::for_caret("%$p%", "i") ~%} @(^ if "%$p%~i"=="" (^ if defined USERPROFILE (^ {% call cd("%$p%USERPROFILE%$p%", 4) -%}^ ) else (^ (echo(%__zoxide_command%: USERPROFILE is not defined) ^>^&2 ^& %$false%^ )^ ) else if "%$p%~i"=="~" (^ if defined USERPROFILE (^ {% call cd("%$p%USERPROFILE%$p%", 4) -%}^ ) else (^ (echo(%__zoxide_command%: USERPROFILE is not defined) ^>^&2 ^& %$false%^ )^ ) else if "%$p%~i"=="-" (^ if defined OLDPWD (^ {% call cd("%$p%OLDPWD%$p%", 4) -%}^ ) else (^ (echo(%__zoxide_command%: OLDPWD is not defined) ^>^&2 ^& %$false%^ )^ ) else for /f "tokens=1,* delims=d" %$p%a in ("-%$p%~ai") do @(^ if not "%$p%b"=="" (^ {% call cd("%$p%~fi", 4) -%}^ ) else if /i not "%$p%CD%$p%"=="%$p%__CD__%$p%" (^ for /f "delims=" %$p%q in ('"zoxide query --exclude "%$p%CD%$p%" -- %$p%~i"') do @(^ {% call cd("%$p%~fq", 5) -%}^ )^ ) else (^ for /f "delims=" %$p%q in ('"zoxide query --exclude "%$p%CD%$p%\" -- %$p%~i"') do @(^ {% call cd("%$p%~fq", 5) -%}^ )^ )^ )^ )^ ) ^&^& %$true% @rem Jump to a directory using interactive search. %$doskey% %__zoxide_command%i = (^ {% call batch::for_caret("%$p%", "i") ~%} @(^ for /f "delims=" %$p%p in ('"zoxide query --interactive -- %$p%~i"') do @(^ {% call cd("%$p%~fp", 3) -%}^ )^ )^ ) ^&^& %$true% {%- when None %} {{ not_configured }} {%- endmatch %} endlocal & set OLDPWD= {{ section }} @rem To initialize zoxide, add this to your configuration or AutoRun command: @rem @rem zoxide init cmd | cmd /d /k >nul