Skip to content

Commit 2ef7e1f

Browse files
committed
Aliases and better Gist compatibilty
1 parent 4574421 commit 2ef7e1f

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

‎PowerShellNotebook.psd1‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ For detailed instructions and examples, click through the "Project Site" link or
8282
#VariablesToExport = '*'
8383

8484
# Aliases to export from this module
85-
AliasesToExport = 'xnb'
85+
AliasesToExport = @('xnb','notebook','codecell','mdcell')
8686

8787
# List of all modules packaged with this module
8888
# ModuleList = @()

‎PowerShellNotebookDSL.ps1‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ $Script:DotNetPSTemplate = @"
2828
"language": "PowerShell"
2929
}},
3030
"language_info": {{
31-
"name": "Powershell",
31+
"name": "PowerShell",
3232
"pygments_lexer": "powerShell",
3333
"mimetype": "text/x-powershell",
3434
"file_extension": ".ps1",
3535
"version": "7.0"
3636
}}
3737
}},
38-
"nbformat_minor": 2,
38+
"nbformat_minor": 4,
3939
"nbformat": 4,
4040
"cells": [
4141
{0}
@@ -119,7 +119,7 @@ function Add-NotebookCode {
119119
120120
#>
121121
[cmdletbinding(DefaultParameterSetName="Default")]
122-
[Alias("Code")]
122+
[Alias("CodeCell")]
123123
param(
124124
[Parameter(Mandatory=$true,Position=0)]
125125
$Code,
@@ -166,15 +166,16 @@ function Add-NotebookCode {
166166
#>
167167
$newBlock = [Ordered]@{
168168
'cell_type' = 'code'
169-
'source' = @($code)
170-
'metadata' = @{}
171-
'outputs' = @()
169+
'execution_count'= 1
170+
'metadata' = @{}
171+
'source' = @($code)
172+
'outputs' = @()
172173
}
173174
if ($outputText) {
174175
$newBlock['outputs'] += @{
175176
"output_type" = "stream"
176177
"name" = "stdout"
177-
"text" = $outputText
178+
"text" = $outputText -replace '\r\n',"`n"
178179
}
179180
Write-Verbose $outputText
180181
}
@@ -189,7 +190,7 @@ function Add-NotebookCode {
189190
$newblock.metadata['azdata_cell_guid'] = (New-Guid).Guid
190191
}
191192

192-
$script:codeBlocks += $newBlock | ConvertTo-Json -Depth 4
193+
$script:codeBlocks += $newBlock | ConvertTo-Json -Depth 10
193194
}
194195

195196
function Add-NotebookMarkdown {
@@ -227,7 +228,7 @@ function Add-NotebookMarkdown {
227228
}]
228229
}
229230
#>
230-
[Alias("Markdown")]
231+
[Alias('MDCell')]
231232
param($markdown)
232233

233234
$script:codeBlocks += [PSCustomObject][Ordered]@{
@@ -323,7 +324,9 @@ function New-PSNotebook {
323324
[Switch]$IncludeCodeResults,
324325
[alias("DNI")]
325326
[switch]$DotNetInteractive,
326-
$RunSpace
327+
$RunSpace,
328+
[alias('PT')]
329+
[switch]$PassThru
327330
)
328331

329332
$script:codeBlocks = @()
@@ -364,6 +367,7 @@ function New-PSNotebook {
364367
else {
365368
if($NoteBookName -notmatch "\.ipynb$") {$NoteBookName = $NoteBookName + ".ipynb"}
366369
$result | Set-Content -Encoding UTF8 -Path $NoteBookName
370+
if ($PassThru) {Get-Item $NoteBookName}
367371
}
368372
}
369373

‎changelog.ipynb‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,13 @@
9292
"2. Can now opt out of creating the GUID. \n",
9393
"3. Will process the `#!about` and `#!Time` magic commands and remove the `#!Pwsh` command.\n",
9494
"4. When being run from New-PsNotebook, if -IncludeCodeResults was specified results are sent to verbose as well as to the notebook\n",
95+
"5. Gist doesn't seem to like CR-LF so I replace CR-LF in output text with LF. \n",
9596
"\n",
9697
"**Changes to `New-PsNotebook`**\n",
9798
"1. Relocated template for the empty notebook and now provide a second one for .NET Interactive notebooks. \n",
9899
"2. Runspace can be provided - remoting FTW! \n",
99100
"3. Now takes the absence of a notebookname as impying `-AsText`. Previously it loooked like specifying neither would cause the file to be named just \\\".ipynb\\\" \n",
100-
""
101+
"4. Added a `PassThru` switch so it can go straight to a gist or whatever. "
101102
]
102103
},
103104
{
@@ -147,7 +148,7 @@
147148
"cell_type": "markdown",
148149
"metadata": {},
149150
"source": [
150-
"**New-Command `Set-NotebookToPs`**\n",
151+
"**New-Command `Set-NotebookToPS`**\n",
151152
"\n",
152153
"Re-writes the metadata in the IPYNB file. \n",
153154
"DotNet Interactive likes to create the file specifying the language as C# and then use a magic command to say \"but this cell is PowerShell\" \n",

0 commit comments

Comments
 (0)