Law
Law

Reputation: 482

How to alias a command to the same command with parameters?

I'm looking for a way to map "emacs" to "emacs -nw" in powershell. I tried this (screenshot below), and it adds it as an alias, but it doesn't work. However, the command "emacs -nw" works before setting the alias.

enter image description here

And I also want a way to save that alias for future sessions (restarting the powershell gets me back to square zero)

EDIT:(aditional info) Also tried creating a function, but when calling that function powershell freezes for a while, then I get the following message (screenshot below) enter image description here

EDIT2:(aditional info) At first, function enw {emacs.exe -nw} (changed function name to 'enw' for explanation purposes) seems to work. But then there's a problem. For the standard emacs, I can type emacs -nw filename.txt, and that would open the file filename.txt in emacs -nw. Calling the function enw filename.txt will not open the filename.txt file, providing the same result as just typing enw.

The solution to this is function enw {Param($myparam) emacs.exe -nw $myparam}

Upvotes: 3

Views: 395

Answers (3)

CB.
CB.

Reputation: 60910

try creating a function:

function emacs {emacs.exe -nw}

then add it to your powershell profile ( $profile )

Upvotes: 2

Matt
Matt

Reputation: 46700

I see you have your answers but I just wanted to spell it out here. You created a recursive function.

By not specifying the .exe as part of the extension PowerShell was able to match emacs back to your function definition. So it would call itself infinitely.

You can see this by checking the results of Get-Command emacs both before and after you register your function.

Upvotes: 0

Sean
Sean

Reputation: 62472

Create a function, but within the function explicitly invoke the .exe :

function emacs {emacs.exe -nw}

Upvotes: 3

Related Questions