zoxide icon indicating copy to clipboard operation
zoxide copied to clipboard

Add support for `cmd.exe` (experimental)

Open mataha opened this issue 2 years ago • 2 comments

See #218.

This PR adds experimental support for cmd.exe using the following Batch techniques:

  • DOSKEY macros
  • for /f with disappearing carets
  • "smart" percent characters

Most of the work was done in a0c6535 - % characters have different meanings depending on the context in which the code is interpreted (command-line vs script), thus the beginning of the template file introduces a macro used to escape them regardless of the situation - even in for statements.

While working on this I had to fix path normalization on Windows in bc947f4, i.e. patching drive letter prefixes to always be uppercase (as that's how the underlying API expects them to be, even though cmd.exe will happily return an unnormalized component from volume path environment variable). A similar problem was encountered in rust-analyzer, which made me provide a fix there. To offset the potential overhead I've bumped dunce to 1.0.4 in 2fdde1c, though most of the changes there are related to licensing and packaging.

To test this, zoxide init cmd is piped into cmd.exe - anything on stderr means failure, e.g.:

')' is not recognized as an internal or external command,
operable program or batch file.

mataha avatar May 10 '23 21:05 mataha

It is ready.

mataha avatar Jun 06 '23 21:06 mataha

This is awesome! I'm learning Batch as I review this, so forgive the intermittent comments.

ajeetdsouza avatar Jun 11 '23 08:06 ajeetdsouza