Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

How to set an alias of a command and it's argument in Windows Powershell?

$
0
0

I am on a Windows 11 machine (Powershell v5.1) and I am trying to alias the rust rewrite of coreutils to appropriate commands in powershell. For example, I need to call coreutils echo to access the echo command and similarly for mv, cat, cp etc. So I wrote a function to output the command string, and I am passing it to the Set-Alias cmdlet.

However I am getting the following error.

echo : The term 'coreutils echo' is not recognized as the name of a cmdlet, function, script file, or operableprogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:1+ echo+ ~~~~+ CategoryInfo          : ObjectNotFound: (coreutils echo:String) [], CommandNotFoundException+ FullyQualifiedErrorId : CommandNotFoundException

Here is my powershell config.

# neovim config aliasfunction Open-NeovimConfig {  $CurrPath = pwd  cd C:\Users\adity\AppData\Local\nvim\lua\user\  nvim .\init.lua  cd $CurrPath  }# coreutils command specifierfunction Coreutils-Cmd($Cmd) {    return "coreutils $Cmd"}Set-Alias nvimc Open-NeovimConfigSet-Alias ls lsd -Option AllScopeSet-Alias echo (Coreutils-Cmd "echo") -Option AllScopeSet-Alias cat (Coreutils-Cmd "cat") -Option AllScopeSet-Alias cp (Coreutils-Cmd "cp") -Option AllScope

EDIT: Based on Santiago's comment, I did the following. However, there is a lot of repeated logic. Any suggestions to improve?

function echo {coreutils echo $args}function cat {coreutils cat $args}function rm {coreutils rm $args}function cp {coreutils cp $args}function mv {coreutils mv $args}

Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>