-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added advice basics #54
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's probably also a more effective and less messy-looking way to split up a string of advice to best suit the console widths...
and we should look at possibly getting the PS Slack and subreddit to chip in and offer their favourite bits and pieces of advice, little tips and so forth.
@@ -0,0 +1,2 @@ | |||
Browsing completion options | |||
When typing a parameter or the value for a parameter, you can hit the TAB key to cycle through the options available. While this is generally well known, it is LESS well known, that by hitting "CTRL"+"SpaceBar" you can show all available options at once and use the cursor keys to navigate to the option you want. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auto-complete is also functional for:
- command names
- filesystem (PSProvider) paths
- .NET types and field or property names
All of which should probably be mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? This ain't about what can be completed for - it's about TAB
vs. CTRL
+SpaceBar
, so I picked the most commonly known examples.
Maybe an explicit mention of it working for all situations where tab is used to cycle through options, but that's about as far as I'd go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just seemed odd that you mentioned it works for parameters and their values, but not... everything else PS offers completion for. ^^
The console experience between Linux and Windows is very different. In PowerShell, if you are crossing the boundary, you can still have a lot of the behavior you are used to, using Set-PSReadlineOption: | ||
Set-PSReadlineOption -EditMode Emacs | ||
Set-PSReadlineOption -EditMode Vi | ||
Set-PSReadlineOption -EditMode Windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A brief summary of what each of those actually do is probably warranted here, if you can one- or two-line each of those. I'm sure there are some differences between Vi and PS's Vi mode, for example, that ought to be mentioned.
|
||
begin | ||
{ | ||
$adviceFolder = Join-Path (Join-Path $script:ModuleFolder 'Data') 'Advice' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're creating the second part of the path, it's best to just do that explicitly, using platform-agnostic slashes (i.e., forward slashes).
Join-Path $script:ModuleFolder 'Data/Advice'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, use parameter names, shame on you! ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a few base cmdlets where yes, I too use positional binding for readability reasons ^^
Had trouble with those forward slashes on some particular windows hosts, so I moved away from them. Probably not relevant for this usecase though.
{ | ||
$adviceFolder = Join-Path (Join-Path $script:ModuleFolder 'Data') 'Advice' | ||
|
||
function Write-Line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a more appropriate name. This is too generic and may be needed by something else at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a function internal command with a single use-case, its name ties perfectly into that foreach loop I'm calling it from.
It would need to be renamed if it became a shared internal function of course.
Maybe to this:?
Write-ConsoleMessage
Would also opt for additional parameteres if we do this:
- Indent left
- Indent right
- Max lines before swallowing text
Wasn't going to bother with the full get-up for a Proof of Concept to show what I had in mind ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, but I think that's worth doing. :)
PSKoans/Public/Invoke-Advice.ps1
Outdated
} | ||
process | ||
{ | ||
$adviceItem = Get-ChildItem $adviceFolder -Recurse | Where-Object PSIsContainer -EQ $false | Where-Object BaseName -Like $Name | Get-Random |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long line; line breaks please!
PSKoans/Public/Register-Advice.ps1
Outdated
{ | ||
[string[]]$lines = Get-Content $PROFILE | ||
$lines += 'Invoke-Advice' | ||
$lines | Set-Content $PROFILE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than bothering to read in the file twice here, you can just use Add-Content
to append aline containing the command to the profile script.
I might also be inclined to suggest use of Select-String for the conditional, but it's probably overkill. It would cut out the Get-Content here, though... but not really accomplishing a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point there, didn't think that through properly
For neater display on small editors
Alright, did a few of the requested changes, commented a lot of the other comments. Also note: I was doing this in a simple manner in order to show it in action. For a final state I would be looking to:
|
Sounds like a good idea. It might be worth linking relevant help topic(s) as well... |
* Added advice basics * Reformat: Broke pipeline into multiline For neater display on small editors * Retionalized appending Invoke-Advice
As discussed in the slack channels: