{%- 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 @(zoxide add -- "%$p%~fa\."))^ {%- 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 --" -%} @echo off & setlocal DisableDelayedExpansion EnableExtensions @if "%~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_z_prefix={{cmd}} @rem Jump to a directory using only keywords. "%$doskey%" %__zoxide_z_prefix% = (^ {% call batch::for_caret("%$p%", "i") ~%} @(^ if "%$p%~i"=="" (^ if defined USERPROFILE (^ {% call cd("%$p%USERPROFILE%$p%", 4) %}^ ) else (^ (echo(%__zoxide_z_prefix%: USERPROFILE is not defined) ^>^&2 ^& %$false%^ )^ ) else if "%$p%~i"=="~" (^ if defined USERPROFILE (^ {% call cd("%$p%USERPROFILE%$p%", 4) %}^ ) else (^ (echo(%__zoxide_z_prefix%: USERPROFILE is not defined) ^>^&2 ^& %$false%^ )^ ) else if "%$p%~i"=="-" (^ if defined OLDPWD (^ {% call cd("%$p%OLDPWD%$p%", 4) %}^ ) else (^ (echo(%__zoxide_z_prefix%: OLDPWD is not defined) ^>^&2 ^& %$false%^ )^ ) else (^ for /f "delims=" %$p%p in ('"zoxide query --exclude "%$p%CD%$p%\." -- %$p%~i"') do @(^ {% call cd("%$p%~fp", 4) %}^ )^ )^ )^ ) ^&^& %$true% @rem Jump to a directory using interactive search. "%$doskey%" %__zoxide_z_prefix%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 {{ section }} @rem To initialize zoxide, add this to your configuration or AutoRun command: @rem @rem zoxide init cmd | cmd /d >nul