简体   繁体   中英

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.

在此处输入图片说明

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) 在此处输入图片说明

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}

创建一个函数,但在函数内显式调用 .exe :

function emacs {emacs.exe -nw}

try creating a function:

function emacs {emacs.exe -nw}

then add it to your powershell profile ( $profile )

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM