Yori Shell. The better CMD replacement
Tags: shell, windows, cmd, tutorial
Published: 2021-02-28 07:15:06

A recurring theme of many articles about Windows 10 is the lack of alternative native shells and terminals. This perpetual statement is not true as there are many shells and terminals for various user needs and windows versions. This article is the first section of a series that will present Windows's solutions about shells, terminals, and command-line installers similar to apt or brew. 

First of all, a lot of confusion is caused by the shell and the terminal's role.  A "*shell*" is a program or a layer that interacts with the operating system's services through a set of commands, while the "*terminal*" is an application that runs and hosts the shells. A lot of frustration about CMD's use was caused by the old and barebone terminal window that hosted it and not so much of the shell itself. 

The [CMD](https://en.wikipedia.org/wiki/Cmd.exe) is a relic from the days of DOS ([COMMAND.COM](https://en.wikipedia.org/wiki/COMMAND.COM) replacement) that has survived in our days. There are plenty of reasons for that. The initial windows users were DOS users; therefore, there was an element of familiarity. Moreover, the CMD is more manageable than UNIX shells' complexity for most developers' simple everyday needs.

Microsoft started to push [PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.1) as the CMD replacement. The PowerShell was a fully object-oriented framework built upon the .NET Framework best suited for the Windows machines administration. Although powerful, it was a complete departure from the CMD simplicity.

Other options for Linux lovers are the bash shell emulation with the easier distribution through [git for windows](https://gitforwindows.org/). Of course, for the most modern and compatible approach for Windows 10,  there is the [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10).

## Installation

[Yori shell](http://www.malsmith.net/yori/) fills the niche between something more straightforward or familiar than the object-oriented PowerShell approach and more modern than the decades-old CMD. 

It is [open-sourced](https://github.com/malxau/yori), and there is a very detailed [guide](http://www.malsmith.net/yori/guide/) if you want to dive into more details.  The installation is pretty straightforward. Just download the latest installation file and run it. 

As the following installation image shows, there are three different install types: install only the `Yori Shell` and its equivalent to CMD commands or include some additional useful tools in addition to the above core installation type. 

![Install Options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m1swkn9zotgl6jpxjak6.png)

## Yori Native Tools

As you have already figured out, Yori Shell not only comes with CMD command replacements but with a set of new tools that you can make your life easier. Some notables tools are :

- *cpuinfo* for displaying processor topology
- *env* for launching a process with a custom environment
- *err* for translating Windows error codes to text
- *mem* for displaying memory usage
- *procinfo* for displaying counters of process utilization
- *ps* for enumerating executing processes
- *shutdn* for shutting down or rebooting a system
- *sponge* for buffering and replaying output to eliminate temporary files
- *timethis* for measuring process execution time
- various tools for VHDs and ISOs files
- *df* for displaying a volume free space
- *du* for calculating disk usage of directories

and my favourites (check image below) 

- a better *dir* command for display the contents of the directory 
- a new *edit* text editor for editing text files in the terminal

![A better dir command for display the contents of the directory](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/444v1edthgdxk6kon7et.png)

![A new text editor for editing text files in the terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0h637d31iiy5acuc6xxo.png)

## Modern Shell Features

The `Yori Shell` has many similarities with the CMD and adds specific features that any respectable modern shell must include.  Two such features are command history and tab completion.

The `Up` and `Down` arrow keys are used to traverse the previously executed commands. The `Ctrl+Up` uses the typed characters to search and match a previous command, and the `Ctrl+Del` deletes the command from history.

![History Completion](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d6a4axxbgr2yvomessgi.gif)

For preserving the history command during different sessions, you may provide a file for storing the commands. The file path is configured in the startup Yori script by setting the variable `YORICOMPLETEPATH`.

The `Yori Shell` from [Malcolm Smith](http://www.malsmith.net/) provides configurable behaviour for tab completion. The default mimics the CMD tab completion by completing the executable first and then tries to match folders or files. The above action can be changed by setting the `YORICOMPLETELISTALL` variable to 1 to provide a list of available matches like the bash. Similarly, setting the `YORICOMPLETEWITHTRAILINGSLASH` variable to 1 adds a trailing slash like the PowerShell. 

Another helpful feature is the ability to jump to special directories in your machine quickly. For example, the command `cd ~` takes you to your home directory or the `cd ~Appdata` to the User's AppData\Roaming directory.   As you will expect, the list of these special directories is comprehensive:

- **~** expands to `Home` directory, as set in `%HOMEDRIVE%%HOMEPATH%`
- **~Appdata** expands to `User's AppData\Roaming directory`
- **~Appdir** expands to `Directory containing the Yori executable`
- **~Commonappdata** expands to `The system application data directory`
- **~Commondesktop** expands to `The system desktop, shared across all users`
- **~Commondocuments** expands to `System documents, shared across all users`
- **~Commonprograms** expands to `System's Start Menu\Programs directory`
- **~Commonstart** expands to `System's Start Menu directory`
- **~Desktop** expands to `User's desktop`
- **~Documents** expands to `User's documents directory`
- **~Downloads** expands to `User's downloads directory`
- **~LocalAppData** expands to `User's AppData\Local directory`
- **~Programs** expands to `User's Start Menu\Programs directory`
- **~Programfiles** expands to `System's Program Files directory`
- **~Programfiles32** expands to `System's Program Files (x86) directory or Program Files in 32-bit environments`
- **~Start** expands to `User's Start Menu directory`
- **~Startup** expands to `User's Start Menu\Programs\Startup directory`
- **~System** expands to `System's Windows\System32 directory`
- **~Windows** expands to `System's Windows directory`

![Go to special directories](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1pf4u57jpwqp778jhbjt.gif)

## Scripting

The scripting story is where it shines. It does not try to provide total compatibility for CMD scripts but instead executes them by CMD. Then, every change to the environment and aliases by the script is applied to the Yori process.

Moreover, it has a native script file extension that is `.ys1`, which provides extra commands that lessen the CMD scripting shortcomings.  It provides a comprehensive outline of the Yori commands by running the `ys /?` command.

![Scripting Help Message](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zr32mf3m7khv1bbf8pzf.png)

## Configuration

The configuration of `Yori Shell` is done, as with most of the shells, by executing initialization scripts during the startup. It seeks the following locations:

Scripts under the `~AppDir\YoriInit.d` directory or any script named `~AppDir\YoriInit*` for system-wide configuration.
Scripts under the `~\YoriInit.d directory` or any script name `~\YoriInit*` for per-user configuration.

## Updating

Another final feature which I am sure many will find useful is the ability to update by using the provide `Yori Package Manager` via the following command:

```shell
ypm -u
```

The `Yori Shell` satisfies my simple dev-based terminal needs; it is simple and fast! Hopefully, you will find the `Yori Shell` as intrigued as I am.