2
Function npp {
    Param([String]$filepath)
    start 'D:\Program Files (x86)\Notepad++\notepad++.exe' &($filepath)
}

Function nteract {
    $file = $args[0]
    start 'D:\Program Files\nteract\nteract.exe' &($file)
}

I wrote two beginner functions for the purpose of recreating the much easier aliases in bash and fish. I have tried two ways of capturing a file argument as shown above. Neither of them work. Instead I receive the following.

Say I am opening the file '.\01 Getting started.ipynb' in nteract.

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
7      Job7            BackgroundJob   Running       True            localhost            Microsoft.PowerShell.Man…
.\01. Getting started.ipynb

This displays in my console, and opens a default instance of nteract with an empty notebook. The same happens with Notepad++ with other files.

Insert a complaint here about how confusing it is to get this functionality working compared to Linux shells. What am I doing wrong?

-==-

EDIT: This question has been answered sufficiently, but I did notice strange behavior the first time I commented out the functions I wrote in my profile.

PS D:\julitory\JuliaBoxTutorials\introductory-tutorials\intro-to-julia> . $profile
PS D:\julitory\JuliaBoxTutorials\introductory-tutorials\intro-to-julia> nteract '.\02. Strings.ipynb'

Id     Name            PSJobTypeName   State         HasMoreData     Location
--     ----            -------------   -----         -----------     --------
5      Job5            BackgroundJob   Running       True            localhost
.\02. Strings.ipynb

For some reason, this occured the first time I commented them out. So I uncommented them, and it began to work again... then, the next time I commented them, they continued to work. I think I'm just too tired for this, but thanks all.

Spencer Gouw
  • 45
  • 2
  • 7

1 Answers1

2

PowerShell has Set-Alias for that purpose. Define, for example:

Set-Alias -Name nteract -Value "D:\Program Files\nteract\nteract.exe"

Then use the alias as:

nteract ".\01 Getting started.ipynb"

Aliases defined this way are only available during the current PowerShell session. For ways to make them persist see How to create permanent PowerShell Aliases .

dxiv
  • 16,984
  • 2
  • 27
  • 49
  • 1
    I have been stupid enough to somehow not try this with my nteract alias, even though I actually had earlier _already written a working alias for notepad++_ and somehow forgotten about it. I was too caught up in my own head. Thanks! EDIT: I spoke too soon. Apparently, it only works if I have both the functions and the aliases defined... it doesn't work with just the aliases. – Spencer Gouw Jun 29 '20 at 15:14