A Case of Sensitivity

A Case of Sensitivity

Unlike the Windows world, Linux is very sensitive about cAsE.

UPDATE July 17th 2020: Working on my next section, I had to make some changed, Reload-MyAliases mentioned here in the post has been renamed to Reload-MyScripts. While I am not modifying this post, I have updated the relevant code section at the bottom. Details can be found in this post.

This means that my plan for using scripts will force me to use the case of the script file name. I don't like that. Mainly because PowerShell has a convention of naming cmdlets with a Verb-Noun scheme, but command line calls usually happen in lower case, with Tab-Completion doing the heavy lifting when available.

So my first scripts are going to address this issue.

Since one major point of reasoning, is the inability to reload a profile effectively (compared to the ease in zsh), I will use Aliases.

Utilizing's PowerShell's Set-Alias, specifically it's -scope parameter, makes it possible to refresh aliases at a script parent's scope.

But before we dive into the code, let's define what are relevant Aliases.

MyAliases

Since PowerShell comes with a set of built-in aliases, I need to distinguish my own aliases. The PowerShell Noun I'll use will be MyAliases.

MyAliases will be automatically created for every file in $MyPSScriptRoot that has a .ps1 extension.

Apart from the scripts, there are some simple substitution aliases that will be defined in the Reload-MyAliases script. To identify those their Description will contain the #MyAlias string.

The Scripts *

Get-MyAliases produces a list of all MyAliases (defined above).
This script also updates a $MyAliasScope variable with the scope level.

Reload-MyAliases makes sure all previously defined MyAliases are removed, and adds only the relevant/currently available ones.
It uses the $MyAliasScope variable to make sure removal and definition all go to the parent scope of the script, otherwise the results will remain in the script's local scope only.

Making it stick

Now, all that's left, is adding the following code to $PROFILE - I usually prefer $PROFILE.CurrentUserAllHosts:

Get-Command Reload-MyAliases -ErrorAction SilentlyContinue | ForEach-Object { Reload-MyAliases }

This will check whether Reload-MyAliases exists, and if it does, it will be called, establishing case-insensitive aliases to otherwise case sensitive script file names upon launch.


* Source Code

Link to latest version At the time of writing
Get-MyAliases commit bfb2e38cc0
Reload-MyScripts commit bfb2e38cc0 Reload-MyAliases
Days gone by. These suitcases have seen better days I feel.  However they still have a sense of style. I love the rustic look of them.
Photo by Belinda Fewings / Unsplash