Skip to content

Commit 410ca54

Browse files
committed
WIP
1 parent bec9717 commit 410ca54

File tree

10 files changed

+138
-252
lines changed

10 files changed

+138
-252
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.(md,txt}]
12+
indent_size = unset
13+
trim_trailing_whitespace = false
14+
15+
[*.{nix,ts,yml,zsh}]
16+
indent_size = 2

Cargo.lock

Lines changed: 58 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ color-print = "0.3.4"
4545

4646
[dev-dependencies]
4747
assert_cmd = "2.0.0"
48-
rstest = { version = "0.18.0", default-features = false }
49-
rstest_reuse = "0.6.0"
48+
rstest = { version = "0.21.0", default-features = false }
49+
rstest_reuse = "0.7.0"
5050
tempfile = "3.1.0"
5151

5252
[features]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ zoxide can be installed in 4 easy steps:
223223
> Add this to the **end** of your config file or AutoRun command:
224224
>
225225
> ```batchfile
226-
> zoxide init cmd | cmd /d /k >nul
226+
> zoxide init cmd --hook none | cmd /d/q/k >nul
227227
> ```
228228
229229
</details>

man/man1/zoxide-init.1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ Add this to the \fBend\fR of your config file (usually \fB~/.bashrc\fR):
1313
\fBeval "$(zoxide init bash)"\fR
1414
.fi
1515
.TP
16+
.B cmd
17+
Add this to the \fBend\fR of your config file or AutoRun command:
18+
.sp
19+
.nf
20+
\fBzoxide init cmd --hook none | cmd /d/q/k >nul\fR
21+
.fi
22+
.TP
1623
.B elvish
1724
Add this to the \fBend\fR of your config file (usually \fB~/.elvish/rc.elv\fR):
1825
.sp

src/shell.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct Opts<'a> {
1111
macro_rules! make_template {
1212
($name:ident, $path:expr) => {
1313
#[derive(::std::fmt::Debug, ::askama::Template)]
14-
#[template(path = $path)]
14+
#[template(path = $path, escape = "none")]
1515
pub struct $name<'a>(pub &'a self::Opts<'a>);
1616

1717
impl<'a> ::std::ops::Deref for $name<'a> {
@@ -103,12 +103,17 @@ mod tests {
103103
let opts = Opts { cmd, hook, echo, resolve_symlinks };
104104
let source = Cmd(&opts).render().unwrap();
105105

106-
Command::new("cmd.exe")
107-
.args(["/a", "/d", "/e:on", "/q", "/v:off", "/k", "@doskey /macros:cmd.exe"])
106+
let assert = Command::new(which::which("cmd.exe").unwrap())
107+
.args(["/d", "/x", "/k"])
108108
.write_stdin(source)
109109
.assert()
110-
.success()
111-
.stderr("");
110+
.success();
111+
112+
if opts.hook != InitHook::None {
113+
assert.stderr("zoxide: hooks are not supported on cmd shell.\r\n");
114+
} else {
115+
assert.stderr("");
116+
}
112117
}
113118

114119
#[apply(opts)]
@@ -117,12 +122,17 @@ mod tests {
117122
let opts = Opts { cmd, hook, echo, resolve_symlinks };
118123
let source = Cmd(&opts).render().unwrap();
119124

120-
Command::new("cmd.exe")
121-
.args(["/a", "/d", "/e:off", "/q", "/v:off", "/k", "@doskey /macros:cmd.exe"])
125+
let assert = Command::new(which::which("cmd.exe").unwrap())
126+
.args(["/d", "/y", "/k"])
122127
.write_stdin(source)
123128
.assert()
124-
.failure()
125-
.stderr("zoxide: unable to init with Command Extensions disabled (see `help cmd` for details)");
129+
.success();
130+
131+
if opts.hook != InitHook::None {
132+
assert.stderr("zoxide: hooks are not supported on cmd shell.\r\n");
133+
} else {
134+
assert.stderr("");
135+
}
126136
}
127137

128138
#[apply(opts)]

src/util.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Fzf {
112112
pub fn spawn(&mut self) -> Result<FzfChild> {
113113
match self.0.spawn() {
114114
Ok(child) => Ok(FzfChild(child)),
115-
Err(e) if e.kind() == io::ErrorKind::NotFound => bail!(Self::ERR_FZF_NOT_FOUND),
115+
Err(e) if e.kind() == io::ErrorKind::NotFound => Err(anyhow!(Self::ERR_FZF_NOT_FOUND)),
116116
Err(e) => Err(e).context("could not launch fzf"),
117117
}
118118
}
@@ -410,38 +410,3 @@ pub fn to_lowercase(s: impl AsRef<str>) -> String {
410410
let s = s.as_ref();
411411
if s.is_ascii() { s.to_ascii_lowercase() } else { s.to_lowercase() }
412412
}
413-
414-
#[cfg(test)]
415-
#[cfg(windows)]
416-
mod tests_win {
417-
use std::path::PathBuf;
418-
419-
use rstest::rstest;
420-
421-
#[rstest]
422-
#[case(r"c:\", r"C:\")]
423-
#[case(r"C:\", r"C:\")]
424-
#[case(r"c:\\.", r"C:\")]
425-
#[case(r"c:\..", r"C:\")]
426-
#[case(r"C:\.\.", r"C:\")]
427-
#[case(r"\\?\C:\", r"C:\")]
428-
#[case(r"\\?\c:\", r"C:\")]
429-
#[case(r"\\?\C:\\\", r"C:\")]
430-
#[case(r"\\?\c:\\.\", r"C:\")]
431-
#[case(r"c:\Windows", r"C:\Windows")]
432-
#[case(r"C:\WINDOWS", r"C:\WINDOWS")]
433-
#[case(r"c:\\\Windows\.", r"C:\Windows")]
434-
#[case(r"C:\$WinREAgent", r"C:\$WinREAgent")]
435-
#[case(r"\\?\c:\\Windows\\.", r"C:\Windows")]
436-
#[case(r"\\?\c:\..\.\windows", r"C:\windows")]
437-
#[case(r"c:\Windows\System32\.", r"C:\Windows\System32")]
438-
#[case(r"c:\WINDOWS\..\..\Windows", r"C:\Windows")]
439-
#[case(r"c:\Windows\..\.\.\..\Temp\..\tmp", r"C:\tmp")]
440-
#[case(r"c:\.\Windows\..\..\Program Files", r"C:\Program Files")]
441-
#[case(r"\\?\C:\\$WinREAgent\\..\Program Files\.", r"C:\Program Files")]
442-
fn resolve_path(#[case] absolute_path: &str, #[case] normalized_form: &str) {
443-
let path = PathBuf::from(absolute_path);
444-
let resolved_path = super::resolve_path(path).unwrap();
445-
assert_eq!(resolved_path.to_str().unwrap(), normalized_form);
446-
}
447-
}

0 commit comments

Comments
 (0)