问题
I'm trying to mimic the subl command in iterm for mac computers in cygwin.
Basically, I want to be able to open a current folder from cygwin by typing subl .
I haven't found any good instructions. I know where my .bashrc file is located. I just dont know what to do to create the command subl and make it so that the path following subl opens with Sublime.
Can anyone help?
回答1:
You'd want to make an alias and source it from bashrc.
Example
Create a file ~/.bash_aliases with:
alias subl='/cygdrive/c/sublime.exe' #make sure this command is correct for you
Now in ~/.bashrc do:
source ~/.bash_aliases
Log out and log back in, and subl . should work
回答2:
Assuming you want correct behaviour when doing subl ~, a simple alias or adding Sublime Text to your PATH will not work.
You can use the following bash function instead (put it in your .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.
Edit: Use subl.exe rather than sublime_text3.exe so that it would detach itself from the terminal.
回答3:
To open files and use Git tools (commit, rebase, tag, ... messages):
#!/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/16c58869319c9a88473ec08cc7989c6b
回答4:
You can also simply add Sublime to your PATH variable. For cygwin, you can:
- Go to your home directory and verify
.bash_profileexists withls -a - Open
.bash_profilewith something likevim .bash_profile - add the line
export PATH=$PATH:"/cygdrive/c/Program Files/Sublime Text 3"(or whatever top level installation folder Sublime is in) - Reopen your terminal and use
sublto verify it works
来源:https://stackoverflow.com/questions/32598753/how-do-i-make-a-command-in-cygwin-to-run-sublime-text