Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

powershell

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}

like image 258
Law Avatar asked May 26 '26 09:05

Law


2 Answers

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

function emacs {emacs.exe -nw}
like image 175
Sean Avatar answered May 30 '26 03:05

Sean


try creating a function:

function emacs {emacs.exe -nw}

then add it to your powershell profile ( $profile )

like image 42
CB. Avatar answered May 30 '26 04:05

CB.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!