Jer*_*rph 41
好的,我发现了一些有用的东西.将批处理文件关联为Vladimir建议不起作用,但bash参数是关键.
简短而甜蜜:与此命令关联:"C:\ cygwin\bin\bash.exe"-li"%1"%*
长版如果你不知道如何:
您可能还想将SH添加到PATHEXT环境变量中:
WinKey + Pause/Advanced/Environment Variables/System Variables/PATHEXT
谢谢你的帮助,伙计们!
小智 15
这是我的解决方案.它适用于我的*.sh脚本,无论它们在目录层次结构中的什么位置.请注意,我在cygpath上调用bash之前cd到cygpath dirname.它只是有效.
assoc .sh=bashscript
ftype bashscript=C:\cygwin\bin\bash.exe --login -i -c 'cd "$(dirname "$(cygpath -u "%1")")"; bash "$(cygpath -u "%1")"'
Run Code Online (Sandbox Code Playgroud)
小智 6
我一直在使用Dragos的解决方案已有一段时间了,我认为它是最好的解决方案,因为它需要在shell脚本中使用"cygpath -u".
然后我想要为.sh和.bash文件提供拖放支持等附加功能.经过一番挖掘,我写了一个.bat,它将.sh和.bash文件关联为"bashscript",并为它们激活Windows资源管理器拖放处理程序.我不得不编辑Dragos的命令以使其处理1个参数(在shell脚本上删除项目的路径).
.bat文件大致如下:
echo Registering .sh and .bash files as "bashscript"...
assoc .sh=bashscript
assoc .bash=bashscript
echo.
echo Setting the run command for the file type "bashscript"...
ftype bashscript=C:\cygwin\bin\bash.exe --login -i -c 'cd "$(dirname "$(cygpath -u "%%1")")"; bash "$(cygpath -u "%%1")" "$(/argshandler.sh "%%2")"'
echo.
echo Activating the drag^&drop capability for "bashscript" files (only 1 dropped item
echo will be passed to the script, multiple items are not supported yet)...
reg add HKEY_CLASSES_ROOT\bashscript\shellex\DropHandler /v "" /t REG_SZ /d "{60254CA5-953B-11CF-8C96-00AA00B8708C}" /f
Run Code Online (Sandbox Code Playgroud)
Cygwin根目录中的"argshandler.sh"脚本只是cygpaths返回它收到的第一个参数,如果没有任何内容则没有任何内容(例如,如果你只是双击一个脚本文件):
#!/bin/bash
if [ ! "$1" == "" ]
then
cygpath -u "$1"
fi
Run Code Online (Sandbox Code Playgroud)
到目前为止,这一切都很顺利.但是,仍有一些缺点可以解决:
不知何故,关于1-dropped-item-only问题,更改参数处理程序脚本以返回类似的内容
"cygpathed-arg1" "cygpathed-arg2" "cygpathed-arg3"
Run Code Online (Sandbox Code Playgroud)
并将Dragos命令的setter更改为类似的东西
...; bash "$(cygpath -u "%%1")" $(/argshandler.sh "%%2" "%%3" ... "%%9")'
Run Code Online (Sandbox Code Playgroud)
(注意argshandler.sh部分周围的""似乎没有正常工作:如果拖动到脚本中的某些项目在其路径中包含空白,则所述路径将在空白处分解为多个参数即使他们每个都用双引号括起来......很奇怪.
是否有任何命令行专业人员能够解决其中一个或两个问题?
| 归档时间: |
|
| 查看次数: |
31541 次 |
| 最近记录: |