[英]How do I make a command in cygwin to run Sublime Text?
I'm trying to mimic the subl
command in iterm for mac computers in cygwin.我正在尝试在 cygwin 中为 mac 计算机模拟
subl
中的subl
命令。
Basically, I want to be able to open a current folder from cygwin by typing subl .
基本上,我希望能够通过键入
subl .
从 cygwin 打开当前文件夹subl .
I haven't found any good instructions.我还没有找到任何好的说明。 I know where my .bashrc file is located.
我知道我的 .bashrc 文件所在的位置。 I just dont know what to do to create the command
subl
and make it so that the path following subl
opens with Sublime.我只是不知道该怎么做来创建命令
subl
并使它的使用 Sublime 打开subl
的路径。
Can anyone help?任何人都可以帮忙吗?
You'd want to make an alias and source it from bashrc.您想创建一个别名并从 bashrc 获取它。
Example例子
Create a file ~/.bash_aliases
with:创建一个文件
~/.bash_aliases
:
alias subl='/cygdrive/c/sublime.exe' #make sure this command is correct for you
Now in ~/.bashrc
do:现在在
~/.bashrc
执行:
source ~/.bash_aliases
Log out and log back in, and subl .
注销并重新登录,然后
subl .
should work应该管用
Assuming you want correct behaviour when doing subl ~
, a simple alias or adding Sublime Text to your PATH
will not work.假设您在执行
subl ~
时想要正确的行为,那么简单的别名或将 Sublime Text 添加到您的PATH
将不起作用。
You can use the following bash function instead (put it in your .bashrc
):您可以改用以下 bash 函数(将其放在您的
.bashrc
):
function subl {
cygpath --windows $@ | sed 's/\\/\\\\/g' | tr '\n' '\0' | xargs -0 -n1 /cygdrive/c/Program\ Files/Sublime\ Text\ 3/subl.exe
}
Note that when passing paths to xargs
you need to 1) escape the backslashes, 2) use the NUL
character as argument delimiter for it to work with paths with spaces.请注意,将路径传递给
xargs
您需要 1) 转义反斜杠,2) 使用NUL
字符作为参数分隔符,以便它处理带空格的路径。
Edit : Use subl.exe
rather than sublime_text3.exe
so that it would detach itself from the terminal.编辑:使用
subl.exe
而不是sublime_text3.exe
这样它就会从终端中分离出来。
To open files and use Git tools (commit, rebase, tag, ... messages):要打开文件并使用 Git 工具(提交、变基、标记、...消息):
#!/bin/bash
# To create in [.babun/]cygwin/usr/local/bin/subl with chmod +x
ARGS=""
while test $# -gt 0
do
ARGS="$ARGS ${1#/cygdrive/[a-zA-Z]}"; # Remove /cygdrive and disk letter from the path
shift
done
/cygdrive/c/Program\ Files/Sublime\ Text\ 3/subl.exe $ARGS
https://gist.github.com/cmalard/16c58869319c9a88473ec08cc7989c6bhttps://gist.github.com/cmalard/16c58869319c9a88473ec08cc7989c6b
You can also simply add Sublime to your PATH variable.您也可以简单地将 Sublime 添加到您的 PATH 变量中。 For cygwin, you can:
对于 cygwin,您可以:
.bash_profile
exists with ls -a
ls -a
验证.bash_profile
是否存在.bash_profile
with something like vim .bash_profile
.bash_profile
有类似vim .bash_profile
export PATH=$PATH:"/cygdrive/c/Program Files/Sublime Text 3"
(or whatever top level installation folder Sublime is in)export PATH=$PATH:"/cygdrive/c/Program Files/Sublime Text 3"
(或 Sublime 所在的任何顶级安装文件夹)subl
to verify it workssubl
来验证它是否有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.