Skip to content

Commit 51b1185

Browse files
committed
Quit if Command Extensions are disabled
1 parent bde3ea8 commit 51b1185

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,8 @@ zoxide can be installed in 4 easy steps:
186186
> Add this to the **end** of your config file or AutoRun command:
187187
>
188188
> ```batchfile
189-
> zoxide init cmd | cmd /d >nul
189+
> zoxide init cmd | cmd /d /k >nul
190190
> ```
191-
>
192-
> **Note**
193-
> zoxide only supports `cmd.exe` with Command Extensions v2 and above.
194191
195192
</details>
196193

src/shell.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,27 @@ mod tests {
104104
let source = Cmd(&opts).render().unwrap();
105105

106106
Command::new("cmd.exe")
107-
.args(["/a", "/d", "/e:on", "/q", "/v:off", "/k", "@doskey", "/macros:all"])
107+
.args(["/a", "/d", "/e:on", "/q", "/v:off", "/k", "@doskey /macros:cmd.exe"])
108108
.write_stdin(source)
109109
.assert()
110110
.success()
111111
.stderr("");
112112
}
113113

114+
#[apply(opts)]
115+
#[cfg(windows)]
116+
fn cmd_dos(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
117+
let opts = Opts { cmd, hook, echo, resolve_symlinks };
118+
let source = Cmd(&opts).render().unwrap();
119+
120+
Command::new("cmd.exe")
121+
.args(["/a", "/d", "/e:off", "/q", "/v:off", "/k", "@doskey /macros:cmd.exe"])
122+
.write_stdin(source)
123+
.assert()
124+
.failure()
125+
.stderr("zoxide: unable to init with Command Extensions disabled (see `help cmd` for details)");
126+
}
127+
114128
#[apply(opts)]
115129
#[cfg(unix)]
116130
fn elvish_elvish(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {

templates/cmd.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
{%- let section = "@rem ==========================================================================\n@rem" -%}
3333
{%- let not_configured = "@rem -- not configured --" -%}
3434

35-
@echo off & setlocal DisableDelayedExpansion EnableExtensions
35+
@(set ^"^") >nul 2>nul && (echo off) || (
36+
echo zoxide: unable to init with Command Extensions disabled ^(see `help cmd` for details^)
37+
) >&2 && exit /b 1 "Command Extensions are disabled" 2>nul
38+
39+
setlocal DisableDelayedExpansion EnableExtensions
3640

3741
if /i "%~f0"=="%~dpnx0" (
3842
set ^"$p=%%<nul"
@@ -156,6 +160,4 @@ endlocal & set OLDPWD=
156160
{{ section }}
157161
@rem To initialize zoxide, add this to your configuration or AutoRun command:
158162
@rem
159-
@rem zoxide init cmd | cmd /d >nul
160-
@rem
161-
@rem Note: zoxide only supports `cmd.exe` with Command Extensions v2 and above.
163+
@rem zoxide init cmd | cmd /d /k >nul

0 commit comments

Comments
 (0)