我想通过双击Windows中的.sh文件在Cygwin中运行一个长的rsync命令。它必须从文件的包含目录(例如/ cygdrive/c/scripts /)开始,以便相对路径起作用。任何人都得到这个工作?如何将.sh文件与Cygwin关联?
注:我刚刚发现了chere,一个管理Windows上下文菜单的Cygwin软件包(Bash Prompt Here)。它可能有一些线索。
我想通过双击Windows中的.sh文件在Cygwin中运行一个长的rsync命令。它必须从文件的包含目录(例如/ cygdrive/c/scripts /)开始,以便相对路径起作用。任何人都得到这个工作?如何将.sh文件与Cygwin关联?
注:我刚刚发现了chere,一个管理Windows上下文菜单的Cygwin软件包(Bash Prompt Here)。它可能有一些线索。
好吧,我发现有用的东西。将一个批处理文件关联为Vladimir建议不起作用,但bash参数是关键。
简短而亲切:准使用此命令:“C:\ cygwin的\斌\ bash.exe” -li “%1” %*
朗版本,如果你不知道如何:
您可能还需要SH添加到您的PATHEXT环境变量:
WINKEY +暂停/高级/环境变量/系统变量/ PATHEXT
感谢您的帮助,伙计们!
有效的解决方案之一是创建一个.bat
文件,该文件将打开cygwin并执行脚本。
执行脚本位于我的主目录的脚本go.sh
:
@echo off
C:
chdir C:\cygwin\bin
bash --login -i ./go.sh
这并不关联.SH文件,但它可能会得到你想要的东西。我开始与启动Cygwin的bash shell中的cygwin.bat批处理文件,并修改它,如下所示:
$ cat test.bat
@echo off
set MYDIR=C:\scripts
C:\cygwin\bin\bash --login -c "cd $MYDIR && echo 'Now in' `pwd`; sleep 15"
这是一个玩具脚本,但你可以修改它来调用的rsync或拨打一个单独的shell脚本。我承认,如果没有MYDIR硬编码,它会更好。有一种方法可以让它自动设置。
哦,是的,当我在Cygwin的bash shell中创建.bat文件时,我注意到我必须实际使用“chmod + x test.bat”才能通过双击启动它。我认为这是设置NTFS权限。如果你只是使用记事本,你不需要那样做。
是的,对MYDIR进行硬编码是一种非起始者,因为我希望其他团队成员能够使用相同的脚本。任何人都可以“自动设置”吗?如果是这样,这看起来像票。在这一点上,它看起来像我们需要DOS脚本专业知识... – Jerph 2008-09-19 21:14:57
查看dos框中的assoc和ftype命令。 这里是我的机器上为JPG格式为例
c:\>assoc .jpg
.jpg=jpegfile
c:\>ftype jpegfile
jpegfile="C:\Program Files\Common Files\Microsoft Shared\PhotoEd\PHOTOED.EXE" "%1"
assoc .sh=bashscript
ftype bashscript="c:\cygwin\bin\bash.exe" "%1"
确保你改变路径在ftype
命令来砸匹配,你有cygwin
安装
对不起,这些命令不适合我。 – Jerph 2008-09-19 22:39:25
这是我的解决方案。无论它们在目录层次结构中的什么位置,它都适用于我的* .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")"'
我只是没有打扰。我使用Crimson Editor将.sh文件关联起来(因为我花了很多时间来处理错误,就像我实际运行它们一样)。现在,只需在“文件类型”>“高级”中使用“组合打开/编辑”即可。如果我知道Crimson Editor使用的是什么DDE代码,那会让事情变得更简单;至于这篇文章,我一直无法找到它,但是。
这让我想起我的Mac时代(1993-2008),当时我曾尝试扫描AppleScript脚本以上的应用程序。
BZT
我用PuttyCyg(Cygwin中窗口真棒腻子)这里是如何得到这一切会:
创建一个批处理脚本,例如。我的机器上我用
C:\Dev\scripts\cygbashrun.bat
与内容
SET CYGWIN=nodosfilewarning
C:\Cygwin\bin\putty.exe -cygterm /bin/bash.exe %1
显然适应包含您PuttyCyg的安装的路径。
然后在Windows资源管理器去工具 - 文件夹选项 - 文件类型
创建“.SH”项,如果没有已经(或取决于你喜欢什么脚本.bash有)。然后高级..
[可选步骤]更改图标,并从选择Cygwin的图标您安装
然后:
工程对我来说就像魅力:O)
我一直在使用Dragos的解决方案一段时间,我认为它是最好的,因为它表明需要在shell脚本中使用“cygpath -u”。
然后我想有像.SH和.bash文件拖放&拖放支持的附加功能。经过一番周围挖我写的.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
在Cygwin的根“argshandler.sh”脚本只是cygpaths回它接收到的第一个参数并没有什么如果没有任何(在所有例如,如果你只是双击了该脚本文件点击):
#!/bin/bash
if [ ! "$1" == "" ]
then
cygpath -u "$1"
fi
这一切workes很好地为止。然而,仍然有一些缺点很好解决:
不知怎的,关于1空投项目,唯一的问题,修改参数处理程序脚本来回馈类似
"cygpathed-arg1" "cygpathed-arg2" "cygpathed-arg3"
和改变Dragos的命令二传手喜欢的东西
...; bash "$(cygpath -u "%%1")" $(/argshandler.sh "%%2" "%%3" ... "%%9")'
(注意argshandler.sh部分周围的“”消失了)似乎不能正常工作:如果某些项目拖到脚本上的路径中包含空白,则所述路径将被分解为多个argume nts在空白,即使他们每个都用双引号括起来......很奇怪。
是否有任何命令行的专业人士谁觉得到它解决这些问题的一个或两个?
Windows Registry Editor Version 5.00
;File:ConfigureShToBeRunUnderExplorer.reg v:1.0 docs at the end
[HKEY_CLASSES_ROOT\Applications\bash.exe]
[HKEY_CLASSES_ROOT\Applications\bash.exe\shell]
[HKEY_CLASSES_ROOT\Applications\bash.exe\shell\open]
[HKEY_CLASSES_ROOT\Applications\bash.exe\shell\open\command]
@="C:\\cygwin\\bin\\bash.exe -li \"%1\" %*"
; This is a simple registry file to automate the execution of sh via cygwin on windows 7, might work on other Windows versions ... not tested
; you could add this setting by issueing the following command: reg import ConfigureShToBeRunUnderExplorer.reg
; Note the path of your bash.exe
; Note that you still have to add the .sh to your %PATHTEXT%
; usage: double - click the file or reg import file
我开发我自己的一个蝙蝠脚本(不是源于其他的答案)的文件类型关联(如* .cygwin)这个.BAT打开,如下所示:
== =文件运行脚本与 - Cygwin的功能于同dir.bat ===
@echo off
REM Info: A script created by Johnny Wong. (last modified on 2014-7-15)
REM It is used to pass a file argument to run a bash script file. The current directory is setting to the path of the script file for convenience.
REM Could be copied to C:\cygwin; and then you manually associate .cygwin file extension to open with this .bat file.
set CYGWIN=nodosfilewarning
C:\cygwin\bin\bash --login -i -c 'cd "`dirname "%~1"`"; exec bash "%~1" %2 %3 %4 %5 %6 %7 %8 %9'
REM finally pause the script (press any key to continue) to keep the window to see result
pause
===文件运行脚本与 - Cygwin的功能于同dir.bat ===
关于语法详细说明使用(如果你有兴趣):
for %%a in (%p%) do set p=%%~a
"%~1"
迫使脚本文件的路径双引号,这样它的文件夹分隔符'\'(在%1中)在被视为转义字符时不会被bash删除。否则,在将其路径中没有空格的文件拖动到该.bat时,它不起作用。中享有:)
这是我使用的命令:
"C:\cygwin\bin\mintty.exe" -w max -h always -t "%1" -e /bin/bash -li -c 'cd "$(dirname "$(cygpath -u "%1")")" && bash "$(cygpath -u "%1")"'
它运行它mintty,最大化设置窗口标题脚本是RAN(Windows路径来它),将目录更改为脚本的位置,运行它并在完成后保持打开状态。
或者,这将标题设置为cygwin的路径的脚本:
"C:\cygwin\bin\mintty.exe" -w max -h always -t "%1" -e /bin/bash -li -c 'printf "\033]0;$(cygpath -u "%1")\007" && cd "$(dirname "$(cygpath -u "%1")")" && bash "$(cygpath -u "%1")"'
批处理脚本来设置该协会为您提供:
在标题Windows路径:
@echo off
assoc .sh=shellscript
ftype shellscript="C:\cygwin\bin\mintty.exe" -w max -h always -t "%%1" -e /bin/bash -li -c 'cd "$(dirname "$(cygpath -u "%%1")")" ^&^& bash "$(cygpath -u "%%1")"'
pause
和标题中的cygwin路径:
@echo off
assoc .sh=shellscript
ftype shellscript="C:\cygwin\bin\mintty.exe" -w max -h always -t "%%1" -e /bin/bash -li -c 'printf "\033]0;$(cygpath -u "%%1")\007" ^&^& cd "$(dirname "$(cygpath -u "%%1")")" ^&^& bash "$(cygpath -u "%%1")"'
pause
如果您的脚本不需要控制台交互,则可以使用cygwin的run.exe完全无窗口地运行它们。只需将命令更改为`C:\ cygwin \ bin \ run.exe“bash -li”%1“%*` – 2011-06-11 06:16:24
有人知道如何在Windows 7中执行此操作吗?”文件类型“选项似乎丢失 – adib 2011-08-24 01:32:05