If it wasn't clear until now, I'm a tinkerer. If it's software, and there is a way to tweak software, I'm going to try it out. Otherwise, this whole adventure seems mute - I mean, why try something that isn't 'the norm'?
My previous posts established the challenge, and initial setup. There is one more prep I need before starting to focus on my server work flow.
The matter of script editing workflow for this shell environment.
I always make it a point to make editing my environments script easy. In Zsh I have a function that loads all the relevant startup scripts into the editor, and when done refresh the shell. This isn't relevant here, as I chose to use script files instead of preloaded functions (I can say after using it for a bit, I really like this approach).
So, my plan is to focus on a helper script just for editing (what I'm calling) MyScript(s).
First I'll establish what accounts for a MyScript:
$MyPSScriptRoot- these should be treated like Function scripts (as in, every script can be called as a function with parameters defined at the top of the script).
* These are also included in MyAliases.
.ps1scripts contained in sub folders of
* These will not be aliased by
- A special case of the above, is the
profile.ddirectory where it's
.ps1scripts will be loaded by
Reload-MyScriptswhich should also be called in
With the definition established, now let's decide how to initiate an editor.
Laziness is Key
NeoVim has been my editor of choice in the Linux console, and so it shall remain. However, I rarely invoked it directly, even when I typed
vim in the Zsh command line, it was usually a function or an alias to a pre-baked call.
This allowed me to have a consistent, comfortable experience.
NeoVim also has syntax highlighters for different languages, PowerShell being one of those. I have not setup those yet, when I do, I'll post on this separately.
Suffice to say, I want to call something that loads the editor exactly the way I like it.
I'm going to preserve this, but creating a
Edit-TextFile script, which will accept a list of file names, open them in my editor of choice (defaulting to NeoVim) preferably in a tabbed interface, and offer the option to elevate with the
This script will call
Edit-TextFile, but instead of receiving full paths to the scripts it will be able to do the following:
- Accept a script name (without the extension) and provide auto-completion for those.
- Accept a new name to start a new script.
- Migrate an existing function into a MyScript file, and open in an editor.
Most importantly, once edit is done,
Reload-MyScripts will be called.
This function will require an additional script named
Export-FunctionSource which takes a function name and outputs the source code of the function. This is for the migration of an existing function feature.
Edit all active profile files, or force editor to open all profile files - even the ones that do not yet exists, with (or without) sudo.
is getting a makeover, and from now on will be
It is still loading MyAliases just like before, only now it also in charge of loading the scripts from the
It is important to source
Reload-MyScripts so that it will load in the shell's scope, and so it calls (actually sources) a new function named
Get‑ScopeDepth which tests for this, and if running in a script sub-scope, it will notify that it should be sourced.
This means that if changes to scripts within
profile.d are made, it is important to source the edit and reload scripts, like:
. Edit-MyScript profile.d/some_script_loaded_with_profile.ps1
Some additional script function