Skip to content

Commit

Permalink
Quit if Command Extensions are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mataha committed Jun 11, 2023
1 parent bde3ea8 commit 51b1185
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,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>

Expand Down
16 changes: 15 additions & 1 deletion src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,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) {
Expand Down
10 changes: 6 additions & 4 deletions templates/cmd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

0 comments on commit 51b1185

Please sign in to comment.