PowerShell上的彩色GHCI输出
不久前,我偶然发现了 this 。但是,由于我正在使用Windows,因此无法运行它。因此,我决定创建一个.ps1
版本,因此我可以在PowerShell中运行它。但是,我一直在遇到以下错误:
Line |
25 | Invoke-Expression (Get-Command ghci).Path $args 2>&1 | `
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| A positional parameter cannot be found that accepts argument 'System.Object[]'.
可以找到我的完整代码在这里谎言如下:
Invoke-Expression (Get-Command ghci).Path $args 2>&1 | `
sed "$load_failed `
$load_done `
$no_instance `
$interactive `
$double_colon `
$right_arrow `
$right_arrow2 `
$parenthesis `
$left_blacket `
$right_blacket `
$double_colon `
$calc_operators `
$string `
$char"
另外,我要转换的原始代码,用shell脚本(.sh)编写,如下所示
exec "`which ghc`" --interactive ${1+"$@"} 2>&1 |\
sed "$load_failed\
$load_done\
$no_instance\
$interactive\
$double_colon\
$right_arrow\
$right_arrow2\
$parenthesis\
$left_blacket\
$right_blacket\
$double_colon\
$calc_operators\
$string\
$char"
,我想澄清一下我已经在我的Powershell。先感谢您。
更新
我已经设法解决了以下提到的错误,多亏了 @mike Anthony 建议使用@args
而不是$ $ args
。但是,我似乎会遇到另一个错误,如下所示:
sed: 13: "s/^Failed, modules load ...": unbalanced brackets ([])
显然,我的代码的以下部分似乎存在错误:
$load_failed="s/^Failed, modules loaded:/$RED&$RESET/;"
$load_done="s/done./$GREEN&$RESET/g;"
$double_colon="s/::/$PURPLE&$RESET/g;"
$right_arrow="s/\->/$PURPLE&$RESET/g;"
$right_arrow2="s/=>/$PURPLE&$RESET/g;"
$calc_operators="s/[+\-\/*]/$PURPLE&$RESET/g;"
$char="s/'\\?.'/$RED&$RESET/g;"
$string="s/`"[^`"]*`"/$RED&$RESET/g;"
$parenthesis="s/[{}()]/$BLUE&$RESET/g;"
$left_blacket="s/\[\([^09]\)/$BLUE[$RESET\1/g;"
$right_blacket="s/\]/$BLUE&$RESET/g;"
$no_instance="s/^\s*No instance/$RED&$RESET/g;"
$interactive="s/^<[^>]*>/$RED&$RESET/g;"
更具体地说:
$string="s/`"[^`"]*`"/$RED&$RESET/g;"
用Shell脚本编写的原始代码读:
string="s/\"[^\"]*\"/$RED&$RESET/g;"
我真的很困惑不平衡的括号因此,任何帮助将不胜感激。
Some time ago, I stumbled upon this. However, since I'm using Windows, I'm unable to run it. Hence, I decided to create a .ps1
version of it so I would be able to run it in PowerShell. However I've been getting the following error:
Line |
25 | Invoke-Expression (Get-Command ghci).Path $args 2>&1 | `
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| A positional parameter cannot be found that accepts argument 'System.Object[]'.
My complete code can be found here and the specific part where the error lies is as follows:
Invoke-Expression (Get-Command ghci).Path $args 2>&1 | `
sed "$load_failed `
$load_done `
$no_instance `
$interactive `
$double_colon `
$right_arrow `
$right_arrow2 `
$parenthesis `
$left_blacket `
$right_blacket `
$double_colon `
$calc_operators `
$string `
$char"
Also, the original code I'm trying to convert, written in shell script(.sh), is as follows
exec "`which ghc`" --interactive ${1+"$@"} 2>&1 |\
sed "$load_failed\
$load_done\
$no_instance\
$interactive\
$double_colon\
$right_arrow\
$right_arrow2\
$parenthesis\
$left_blacket\
$right_blacket\
$double_colon\
$calc_operators\
$string\
$char"
And I'd like to clarify that I have installed sed
on my PowerShell. Thank you in advance.
Update
I've managed to resolve the earlier mentioned error thanks to @Mike Anthony's suggestion to use @args
instead of $args
. However, I seem to be getting another error as shown below:
sed: 13: "s/^Failed, modules load ...": unbalanced brackets ([])
Apparently there seems to be an error with the following part of my code:
$load_failed="s/^Failed, modules loaded:/$RED&$RESET/;"
$load_done="s/done./$GREEN&$RESET/g;"
$double_colon="s/::/$PURPLE&$RESET/g;"
$right_arrow="s/\->/$PURPLE&$RESET/g;"
$right_arrow2="s/=>/$PURPLE&$RESET/g;"
$calc_operators="s/[+\-\/*]/$PURPLE&$RESET/g;"
$char="s/'\\?.'/$RED&$RESET/g;"
$string="s/`"[^`"]*`"/$RED&$RESET/g;"
$parenthesis="s/[{}()]/$BLUE&$RESET/g;"
$left_blacket="s/\[\([^09]\)/$BLUE[$RESET\1/g;"
$right_blacket="s/\]/$BLUE&$RESET/g;"
$no_instance="s/^\s*No instance/$RED&$RESET/g;"
$interactive="s/^<[^>]*>/$RED&$RESET/g;"
and more specifically:
$string="s/`"[^`"]*`"/$RED&$RESET/g;"
The original code written in shell script reads:
string="s/\"[^\"]*\"/$RED&$RESET/g;"
I'm really confused where the unbalanced brackets are so any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您根本不需要Invoke-Expression,只需使用GHCI就好像您在命令行中一样(假设GHC已添加到路径变量中)
I don't think you need Invoke-Expression at all, just use ghci as if you would on the command line e.g. (assuming ghc is added to your PATH variable)
似乎有两层逃脱。
尝试:
而不是:
Seems like there are two layers of escaping going on.
Try:
Instead of: