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 operable
program. 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 alias
function Open-NeovimConfig {
$CurrPath = pwd
cd C:\Users\adity\AppData\Local\nvim\lua\user\
nvim .\init.lua
cd $CurrPath
}
# coreutils command specifier
function Coreutils-Cmd($Cmd) {
return "coreutils $Cmd"
}
Set-Alias nvimc Open-NeovimConfig
Set-Alias ls lsd -Option AllScope
Set-Alias echo (Coreutils-Cmd "echo") -Option AllScope
Set-Alias cat (Coreutils-Cmd "cat") -Option AllScope
Set-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}