malxau / yori

Yori is a CMD replacement shell that supports backquotes, job control, and improves tab completion, file matching, aliases, command history, and more.
http://www.malsmith.net/yori/
MIT License
1.23k stars 30 forks source link

CD Improvement #122

Closed PIRANY1 closed 6 months ago

PIRANY1 commented 6 months ago

In a Normal Terminal Session you can use "cd.." without the space between "cd" and ".." to go a Directory back. Is this Possible too in yori?

malxau commented 6 months ago

It’s currently not fully possible. You could use alias cd..=cd .. but that only works for one specific path.

When writing Yori I was trying to avoid “special” parsing rules that apply per command. The goal was to allow other developers to write commands – internal or external – so special rules went against the goal.

Looking at CMD now though, it is following rules, just subtle and difficult to understand ones. I don’t understand them fully. But roughly, it looks like

  1. Check if the command is a builtin internal, and if so, execute it.

  2. Check if the command refers to an executable file, including extension, and if so, execute that.

  3. Re-parse the command and treat “.”, “/” and “\” as seperators. Text at the separator is moved to become the first argument. Check if the text before the separator is a builtin.

  4. If it’s not a builtin, go back and look for path/pathext matches.

It still seems inconsistent though. “Echo..” will echo “.”; “echo\” will not echo anything (ie., the first char seems ignored.) But cd can’t skip the first character.

Note there’s a lot of ambiguity in these rules. “cd\foo.exe” might mean “execute foo.exe” or might mean “change directory to foo.exe” depending on whether cd\foo.exe exists. It also seems to execute real executables regardless of file extension, so “cd.foo” can change directory to .foo or execute “cd.foo” as a real executable.

Anyway, Yori’s evaluation is different. It also can’t solve the ambiguity, so my advice is to use these shortcuts as accelerators where you trust the directory contents.

So, I just pushed a change which does something similar:

  1. Check if the command is an executable file, including adding path and pathext, and if something is found execute it. (This was preexisting behavior.)

  2. Check if the command is a builtin, and if so, execute that. (This was preexisting behavior.)

  3. Re-parse the command and treat “.”, “/” and “\” as seperators. Text at the separator is moved to become the first argument. Resolve any alias in the command. After alias resolution, check if it’s a builtin command, and if so, execute it.

Note that in CMD, aliases are really evaluated by conhost and have no awareness about these rules. In Yori, many built-ins are really aliases (eg. “cd” is an alias for “chdir” so if aliases weren’t expanded, this wouldn’t work.)

PIRANY1 commented 6 months ago

Okay Thank you