# the original version that didn't parse
# because ',' made number endings ambiguous
'1,000,2,000,3,000,0,000,1,000,2,000,3,000,0,000' -split '\,'
| Join-String -sep ' ' -SingleQuote
| Label 'original' -Before 1
'1000', '2000', '3000', '0', '1000', '2000', '3000'
| Join-String -sep ' ' { '{0:n0}' -f @( $_ -as 'int' ) } -SingleQuote
| Label 'should be' -Before 1 -After 1
$result ??= @{}
( $result.Steps1 ??= ai '# first 100 numbers modulous 4, multiplied by a factor of 1e6' )
| renderNice | Label 'Step1' -bef 1
hr
label 'step3' -after 1 'This time it''s parsable, but, the numbers are not the same different.'
$result.Steps3 -split ',' -replace "'", '' | renderNice
PowerQuery has metadata that you don’t normally see. For example, take the function Table.FromRecords
Create a new blank query, and set the value to a function’s name. When you reference a function without arguments or parenthesis, it displays documentation. ( It’s mostly the same as the online docs )
Where does this come from? A lot of it is generated by metadata on the function’s type itself.
Let’s start drilling down. Using the function Value.Type you can view the type’s definition
It doesn’t seem very useful at first. The data we want is from the metadata, the Ascribed types.
The part that comes after meta operator is a regular record
let
Text.ReplacePartialMatches = Value.ReplaceType( Text.ReplacePartialMatches_impl, Text.ReplacePartialMatches.Type ),
Text.ReplacePartialMatches.Type = type function(
source as text,
mapping as Table.Type
) as text meta [
Documentation.Name = "Text.ReplacePartialMatches",
Documentation.LongDescription = Text.Combine({
"Test strings for partial text matches. Replace the entire cell/value with the new replacement text.",
"",
"Mapping table requires two columns: <code>[Partial]</code> and <code>[New Value]</code> "
}, "<br>")
],
Text.ReplacePartialMatches_impl = ( source as text, mapping as table ) as text =>
// todo: performance, exit early on first replacement
let
mappingList = Table.ToRecords( mapping ),
result = List.Accumulate(
mappingList,
source,
(state, cur) =>
if Text.Contains( state, cur[Partial], Comparer.OrdinalIgnoreCase )
then cur[New Value] else state
)
in result
in
Text.ReplacePartialMatches
Goto /c/foo/bar
# go back
> Goto -Back
> Goto '-' # normal cd history works too
> Goto '+'
# Goto the world
$Profile | goto # go to string's path
Get-Item $PROFILE | goto # cd to the FileItem's path
gcm EditFunc | goto # jump to function declaration
gmo NameIt | Goto # go to module's folder
[CompletionResult] | goto # to docs for
# <https://docs.microsoft.com/en-us/dotnet/api/System.Management.Automation.CompletionResult>
# Open git repos in browser
goto git microsoft/powerquery-parser | goto
goto git@github.com:microsoft/powerquery-parser.git | goto
# goto the newest log
Get-ChildItem 'c:\root\manyLogs' -Recurse
| Sort LastWriteTime -desc -top 1 | goto
Pwsh Cli
Display all parameters My favorite hotkey, ctrl+spacebar
Is it a bug, or, is the extra y-axis padding working as intended in a situation where intended is not intended ( ie: column count orders of magnitude larger than the terminal’s column count )
When you run run the ‘default settings’ command, it builds a new one — this means it’s always up to date. It includes settings from all enabled addons.
Command Palette: The Only Hotkey You Need to Remember.
Can’t remember what key formats without saving? No problem, f1 -> forsave and it will come up.
First open the command palette using either Hotkey. Then start typing for a match. Preferences: Open Settings is your settings.json
The UI editor is pretty good, it will give you access to most settings. To control everything, or use language-specific overrides, you’ll need to use the Json editor.
Go to Symbol: The Secret to Navigating giant JSON files
It’s better than using a regular search ctrl+f . If you searched for ‘fontsize’ not only will you get every setting, but, lots of comments as well. When there’s duplicate settings, the bottom one has priority. If you like customizing, you may end up with duplicated keys. This instantly lets shows you which is the final one. Even if they are 3000 lines apart.
Default settings is huge. Using go to symbol gives you cleaner results verses using find.
Control+Space: The 2nd Best Hotkey
As you’re editing, ctrl+space will fuzzy search every possible setting. Hit it a 2nd time to toggle the documentation.
Autocomplete everything!
Searching Keybindings by Name or Command by name
To find which commands run on a chord, use reverse lookup
Suggested PowerShell Config
I tried keeping it short, I recommend checking these settings for PowerShell. If you want to control autocomplete or suggestions , this config has notes on some properties to check out.
{
// this file is almost the same as
//<https://github.com/ninmonkey/dotfiles_git/blob/614fc06cd8b989e8438cba6cae648605fae2491a/vscode/User/nin10/Code/minimum-config/powershell.settings.json>
"workbench.settings.editor": "json", // good for editing, [ctrl+,]
// will by default open your global settings as JSON instead of UI
// improve code quality
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.codeFormatting.useConstantStrings": true,
"powershell.codeFormatting.useCorrectCasing": true,
// I have this enabled for most languages
"editor.formatOnSave": true,
// some people are pretty polarized on which style to use,
// So I have both styles and variants to try
"editor.wordSeparators": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?", // combine $ and -
"editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?", // causes splat-expression etc to break
"editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/?", // break on $ and -
"editor.wordSeparators": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?", // combine $ and -
"editor.wordSeparators": "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?",
// If you don't like snippets, you can disable them for as specific language, leaving the others
// the blog isn't rendering the next line, it should say
// "[power shell]" as the key If you don't like snippets, you can disable them for as specific language, leaving the others
"[powershell]": {
"editor.semanticHighlighting.enabled": false,
"editor.snippetSuggestions": "bottom",
"editor.snippetSuggestions": "none",
"files.encoding": "utf8bom",
"files.trimTrailingWhitespace": true,
},
/*
Adds autocompletion and validation to any .Format.ps1xml and .Types.ps1xml files.
It uses the addon: 'redhat.vscode-xml'
*/
"editor.suggest.preview": true, // interesting but can be jarring
],
"powershell.integratedConsole.suppressStartupBanner": true,
"powershell.powerShellDefaultVersion": "PowerShell (x64)",
"powershell.promptToUpdatePowerShell": false,
// Specifies the path to a PowerShell Script Analyzer settings file. To override the default settings for all projects, enter an absolute path, or enter a path relative to your workspace.
"powershell.scriptAnalysis.settingsPath": "C:/Users/monkey/Documents/2021/dotfiles_git/powershell/PSScriptAnalyzerSettings.psd1",
// "powershell.scriptAnalysis.settingsPath
// Autocomplete and a schema/validation for
// powershell's "types.ps1xml" and "format.ps1xml" files
"xml.fileAssociations": [
{
"systemId": "https://raw.githubusercontent.com/PowerShell/PowerShell/master/src/Schemas/Format.xsd",
"pattern": "**/*.Format.ps1xml"
},
{
"systemId": "https://raw.githubusercontent.com/PowerShell/PowerShell/master/src/Schemas/Types.xsd",
"pattern": "**/*.Types.ps1xml"
}
}
# For every file fd finds, print the first 15 lines
PS> fd --exec-batch bat --line-range=:15 --paging=always
# forcing paging /on/off
PS> fd --exec-batch bat --line-range=:15 --paging=never
Pwsh🐒> # test whether it's resolved by coerce to [type]
'catman' -as 'type' -is 'type'
'batman' -as 'type' -is 'type'
True
False
Pwsh🐒> # test whether it's resolved by coerce to [type]
'catman' -as 'type' -is 'type'
'batman' -as 'type' -is 'type'
True
False
# after
Pwsh🐒> @(
# Declaring a new type in inside a [ScriptBlock]
& {
class batman { [string]$Name }
[batman]
}
# verses dotsourcing a type into the current scope
. {
class catman { [string]$Name }
[catman]
}) | ft -AutoSize
Namespace: <4cf9efd5>
Access Modifiers Name BaseType
------ --------- ---- --------
public class batman object
Namespace: <f2200555>
Access Modifiers Name BaseType
------ --------- ---- --------
public class catman object