Quit if Command Extensions are disabled

This commit is contained in:
mataha 2023-06-12 01:19:24 +02:00
parent 1ee0195a0d
commit 8d61617c6a
3 changed files with 22 additions and 9 deletions

View File

@ -219,11 +219,8 @@ zoxide can be installed in 4 easy steps:
> Add this to the **end** of your config file or AutoRun command:
>
> ```batchfile
> zoxide init cmd | cmd /d >nul
> zoxide init cmd | cmd /d /k >nul
> ```
>
> **Note**
> zoxide only supports `cmd.exe` with Command Extensions v2 and above.
</details>

View File

@ -105,13 +105,27 @@ mod tests {
let source = Cmd(&opts).render().unwrap();
Command::new("cmd.exe")
.args(["/a", "/d", "/e:on", "/q", "/v:off", "/k", "@doskey", "/macros:all"])
.args(["/a", "/d", "/e:on", "/q", "/v:off", "/k", "@doskey /macros:cmd.exe"])
.write_stdin(source)
.assert()
.success()
.stderr("");
}
#[apply(opts)]
#[cfg(windows)]
fn cmd_dos(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
let opts = Opts { cmd, hook, echo, resolve_symlinks };
let source = Cmd(&opts).render().unwrap();
Command::new("cmd.exe")
.args(["/a", "/d", "/e:off", "/q", "/v:off", "/k", "@doskey /macros:cmd.exe"])
.write_stdin(source)
.assert()
.failure()
.stderr("zoxide: unable to init with Command Extensions disabled (see `help cmd` for details)");
}
#[apply(opts)]
#[cfg(unix)]
fn elvish_elvish(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {

View File

@ -32,7 +32,11 @@
{%- let section = "@rem ==========================================================================\n@rem" -%}
{%- let not_configured = "@rem -- not configured --" -%}
@echo off & setlocal DisableDelayedExpansion EnableExtensions
@(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=%%<nul"
@ -156,6 +160,4 @@ endlocal & set OLDPWD=
{{ section }}
@rem To initialize zoxide, add this to your configuration or AutoRun command:
@rem
@rem zoxide init cmd | cmd /d >nul
@rem
@rem Note: zoxide only supports `cmd.exe` with Command Extensions v2 and above.
@rem zoxide init cmd | cmd /d /k >nul