Modify the `edit` binary in os x to a different editor - macos

On the command line, I can type edit <folder/file name> and it will open in TextWrangler, which I haven't used in ages. I'm not sure how the edit binary got there — I use oh-my-zsh, potentially relevant. I wanted to change subl to edit (nicer to type) and discovered it already existed.
I uninstalled TextWrangler and now I get the error
edit: error: -10814
LaunchServices could not locate your copy of TextWrangler.
I've been looking around for how to modify the LaunchServices database and I've rebuilt it but I still get the error. Running which edit gives me /usr/local/bin/edit fwiw.
What controls this association and how can I switch it to Sublime Text?

If you were to run ls -al /usr/local/bin/edit you'd see this:
lrwxr-xr-x 1 root wheel 52 Apr 15 2012 /usr/local/bin/edit -> /Applications/TextWrangler.app/Contents/Helpers/edit
Therefore, it looks like edit is a built-in command-line program for TextWrangler, just like subl is for Sublime, or mate is for TextMate. Of course, there's nothing stopping you from deleting the symlink, then making a new one pointing to subl if you want to.

To switch, you can run the following commands:
rm /usr/local/bin/edit
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/edit
In my case, I had replaced TextWrangler for BBEdit, so I just did those commands but with /Applications/BBEdit.app/Contents/Helpers/bbedit_tool instead of the Sublime (subl) one.

Related

Sublime Text 3 on command Line

I have installed zsh and ohmyzsh. I followed an instruction to open sublime text 3 on the commandline by typing sublime in the folder.
Instead of typing the whole 'sublime' word, can I just open it by typing 'subl' to open sublime? If so how on ohmyzsh?
When I execute echo $PATH, it returns /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Thank you in advance for helping out.
********************Edited********************
For those who are having issues try the EASY way.
Fidner go to the root dir
Application
find sublime right click 'show content'
contents/sharedSupport/bin ==> there should be a file 'subl'
now go back to root dir and usr/local/bin and look for subl or sublime. delete those and paste the recently copied subl.
Should work like a charm.
I think you're looking for a way to set an alias in zsh: https://askubuntu.com/questions/31216/setting-up-aliases-in-zsh
Create a symlink from Sublime binary to /usr/local/bin. Symlink can be any name
This worked for me. I followed the path to where sublime was located in my /Applications directory and created a symbolic link to my local executable programs. It should work for you too. If /Applications/Sublime Text.app/Contents/SharedSupport/bin/ does not lead to subl than it will not work. You might need to sudo to cd and to ln -s.
ln -s /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
I found this information from this StackOverflow Question. Also, this Unix answer helped me understand the /usr/local/bin/ path better. This answer is great too. I hope it helps.

I cannot able to connect sublime text 2 from my terminal

When I am writing open subl in my terminal it's showing The file /user/imtiaz/sublime does not exis can some one please help me for this one thanks
Assuming your account has administrator access, run the following command from Terminal:
sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl
The sudo command will ask you to enter your password, which you should do. The symbolic link will be created in /usr/bin, which is already in your path. You should now be able to run
subl filename.ext
and open the filename in Sublime.
If you're just getting started with Sublime, however, I would strongly recommend using Sublime Text 3 instead. It has many major improvements over ST2, and even though it's technically still labeled "Beta", it's rock-solid. I've been using it for over 2 years without any major issues. ST2 has some bugs in it, which will never get fixed. Once installed, the first thing you need to do is install Package Control, which allows you to easily manage plugins. Many plugins now only support ST3, or their ST2 versions are no longer being updated.
If you do install ST3, change the above command to
sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/bin/subl
as the app is named Sublime Text.app instead of Sublime Text 2.app.

Sublime Text 3 'subl' command still linked to Sublime Text 2

This is driving me crazy. I'm running OSX and until today I had Sublime Text 2 installed. After installing Sublime Text 3, when I enter the 'subl' command the terminal logs:
Unable to find application named 'Sublime Text 2'
I've tried everything. I've tried
$ rm ~/bin/subl
Then
$ ln -s /Applications/Sublime\ Text\ 3.app/Contents/SharedSupport/bin/subl ~/bin/subl
I've also tried going in to usr directly and removing the subl command. When I do this, the subl command will sometimes work while I remain in one directory, but once I switch directories it goes back to giving me the message
Unable to find application named 'Sublime Text 2'
With Sublime Text 2 I had subl entered as an alias. I also tried going in and unaliasing subl like this:
unalias subl
And I've tried re-creating the alias using
/Applications/Sublime\ Text\ 3.app/Contents/SharedSupport/bin/subl
Again, this will work for a while, but once I change directories it stops working.
Any advice on what to try next? I'm at a loss. I can't understand why it works for a while, then stops working.
Check your .bashrc file, and .bash_profile and see if it's aliased in there. Both of these are in your home directory ~.
nano ~/.bashrc
nano ~/.bash_profile
No need to sudo as you own these documents.

Sublime 3: Subl not working

Before today I had Sublime 2 and 3 on my computer. When I ran the subl command in the terminal it would always open Sublime 2, which I never use anymore. Therefore I got rid of Sublime 2. Now my subl command does not work at all. All I get is subl command not found.
I understand that I have to put a subl binary file into my bin folder. I was just wondering what might be the best way to go about doing that. Any insight on this particular instance would help.
Thanks in advance,
According to their website:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
(The command is almost identical to the one for version 2.)
If you have a fresh install of OS X, this will probably fail for you. First, create a ~/bin directory under your home and add it to your path. This will vary by your shell, but if you use bash..
mkdir ~/bin
echo "export PATH=$PATH:~/bin" >> ~/.bash_profile
source ~/.bash_profile
Then you should be able to run the ln command and subl to your hearts content.
As a side note, a simplified version of this can be accomplished with the open command for any app. Try open -a TextEdit hello.txt for similar effect. I've aliased this for a hex editor that didn't offer a CLI launcher like subl.
Try this: (it worked for me)
alias subl="'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'"
alias nano="subl"
export EDITOR="subl"
Shortly after I posted this question I found the answer. The issue was that because the subl file in my bin or binary folder was tied to Sublime 2, when I uninstalled Sublime 2 it also uninstalled that binary.
All I did was copy the subl file from Sublime 3 into the bin or binary folder. I did have use the terminal in order to get down to the bin folder. Once I opened both folders with the terminal I just copied the subl binary from Sublime 3 to my binary folder.

Sublime Text 2: subl shell command often fails to open files

I have Sublime Text 2 installed on a Mac, and have made a link on the command line as described in the docs.
When opening files from the terminal, as in:
$ subl foo.txt
A Sublime Text window will open, but inside that window foo.txt will only open about one out of every three times or so. I've tried moving the link to a different folder in the path, creating it with sudo, etc., but no luck so far.
Any idea how to fix this?
Had the same problem for a while now. Add the following line to your .bash_profile:
alias subl='subl && sleep 0.1 && subl'
Now you can use subl filename_to_edit to open it.
If you are not sure if you configured subl command correctly, do the following. Run the first command for ST3 or the second for ST2:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Make sure that ~/bin is in your $PATH. Then do the first step with .bash_profile.
Finally works as it should! Credit goes to these guys and chrisf for improvement.
I remember running into problems with subl before. And had to come up with a function to see if Sublime is running, if not launch it, see if it loaded. Then use "rmate" bash script and the associated "rsub" Sublime Text Package plugin to load in the specified file. However you should be able to use the OSX open command should work for what you need. I would also give the latest Sublime Text 3 Beta a try.

Resources