Using BBEdit as a *nix remote text editor?

950 views
Skip to first unread message

Andrew B

unread,
Aug 30, 2014, 5:46:22 PM8/30/14
to bbe...@googlegroups.com
Hello, I am new to BBEdit and have scanned the docs and searched for an answer to my questions, but perhaps the fastest way is just to ask here. I am likely going to be working quite a bit with remote Linux dev environments in the near future, and I cannot abide emacs, vi, vim, gedit and so forth. I would very much like to be able to use an OSX based text editor as my weapon of choice, and BBEdit looks like a very good candidate... if I can get it to do a few magic tricks:

* Is it possible to invoke BBEdit to edit a file using a command on a remote Linux machine? The bbedit tool seems to do exactly this on the local OSX machine, but I'm wondering if anyone has magic that could accomplish the same result remotely.

* Can the BBEdit shell workspace be directed to any SSH connection?

* I am assuming that between the open via ftp/sftp, and the mounting of remote file systems, BBEdit should be able to access and edit the remote files. Are there any gotchas here I should be aware of?

(apologies if this is a duplicate post, my first attempt seems to have gone AWOL)

Charlie Garrison

unread,
Aug 30, 2014, 6:50:25 PM8/30/14
to bbe...@googlegroups.com
Good morning,

On 30/08/14 at 2:46 PM -0700, Andrew B
<andrew.e....@gmail.com> wrote:

>* Is it possible to invoke BBEdit to edit a file using a command on a
>remote Linux machine? The bbedit tool seems to do exactly this on the
>local OSX machine, but I'm wondering if anyone has magic that could
>accomplish the same result remotely.

I'm not aware of anything to do this. There have been past
attempts (even by me) but nothing successful. The best I came up
with was automating the process of:

- scp localfile osxhost:localfile
- ssh osxhost bbedit -wait --resume localfile
- scp osxhost:localfile localfile

It was too fragile though; it was quite a while ago and I don't
recall the problems.

I'd love to hear someone else saying they have a solution for
this one. Would be great if I could set EDITOR on remote
machines to point back to bbedit.

>* Can the BBEdit shell workspace be directed to any SSH connection?

The worksheet is not a TTY, so you cannot have an ssh *session*.
You can send commands to remote servers via ssh from a worksheet
(assumes ssh key login). I use this method quite a lot to (eg)
set permissions for files on remote server, or restart a running
process on remote server, etc. I also use worksheet to copy
files to remote server using rsync; especially handy for
mirroring sites.

>* I am assuming that between the open via ftp/sftp, and the mounting of
>remote file systems, BBEdit should be able to access and edit the
>remote files. Are there any gotchas here I should be aware of?

There may be some gotchas, but none I think you need to be aware
of. BBEdit has quite good handling of files on remote volumes. I
sometimes use the built-in s/ftp tools; I used to use external
s/ftp (Interarchy) almost exclusively; I now use mounted remote
volumes with ExpanDrive.

[The new version of ExpanDrive has introduced some strange race
conditions with its new local file cache; I've not found the
reproducible steps yet. Anyone else seeing problems with new
ExpanDrive 'modifying files since last save'?]

As someone new to BBEdit, you will bring a fresh perspective to
editing files on remote servers. I look forward to hearing what
solution(s) you find work best for you.


Charlie

--
Charlie Garrison <garr...@zeta.org.au>
github.com/cngarrison metacpan.org/author/CNG

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt

Gregory Shenaut

unread,
Aug 30, 2014, 8:30:08 PM8/30/14
to bbe...@googlegroups.com
Would sshfs (in macports) be an option? I used this once in 2009 to do something similar.

Greg Shenaut
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or would like to report a problem, please email
> "sup...@barebones.com" rather than posting to the group.
> Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
>
> --- You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To post to this group, send email to bbe...@googlegroups.com.

Jan Erik Moström

unread,
Aug 31, 2014, 2:28:35 AM8/31/14
to bbe...@googlegroups.com
At work I regularly edit files that resides on the server. I do it in
one of two ways - either Interarchy using the edit command or mounting
the remote server using ExpanDrive. Both these solutions use sftp (in
my case).

Andrew B

unread,
Aug 31, 2014, 10:07:51 AM8/31/14
to bbe...@googlegroups.com
Thanks guys... the portion of the problem I'm least concerned with is the actual editing. I've been doing the mount and edit thing for a couple of years, and after some fiddling around it generally works. Need to make it more slick in case I have to connect to multiple machines more easily, but I think I can work that out.

The bigger issue is all those times when you're at the command line of an ssh session and you need to edit a file, or a tool like git wants to invoke an editing session. It sounds like nobody yet has a good solution for that, which is disappointing. I guess I'll have to come up with something for that myself.

Rich Siegel

unread,
Aug 31, 2014, 10:19:26 AM8/31/14
to bbe...@googlegroups.com
On Sunday, August 31, 2014, Andrew B <andrew.e....@gmail.com>
wrote:

>The bigger issue is all those times when you're at the command line of
>an ssh session and you need to edit a file, or a tool like git wants
>to invoke an editing session. It sounds like nobody yet has a good
>solution for that, which is disappointing. I guess I'll have to come
>up with something for that myself.

This may be adaptable to current need: <https://github.com/alexkazik/textwrangler-remotecontrol>.

R.
--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <http://www.barebones.com/>

Someday I'll look back on all this and laugh... until they
sedate me.

Fletcher Sandbeck

unread,
Aug 31, 2014, 1:00:02 PM8/31/14
to bbe...@googlegroups.com
Try installing pico or nano. They are a lot more friendly than vi.

[fletcher]

On Aug 31, 2014, at 7:07 AM, Andrew B <andrew.e....@gmail.com> wrote:

> Thanks guys... the portion of the problem I'm least concerned with is the actual editing. I've been doing the mount and edit thing for a couple of years, and after some fiddling around it generally works. Need to make it more slick in case I have to connect to multiple machines more easily, but I think I can work that out.
>
> The bigger issue is all those times when you're at the command line of an ssh session and you need to edit a file, or a tool like git wants to invoke an editing session. It sounds like nobody yet has a good solution for that, which is disappointing. I guess I'll have to come up with something for that myself.
>

Charlie Garrison

unread,
Aug 31, 2014, 7:10:55 PM8/31/14
to bbe...@googlegroups.com
Good morning,

On 31/08/14 at 7:07 AM -0700, Andrew B
<andrew.e....@gmail.com> wrote:

>Thanks guys... the portion of the problem I'm least concerned with is
>the actual editing. I've been doing the mount and edit thing for a
>couple of years, and after some fiddling around it generally
>works. Need to make it more slick in case I have to connect to multiple
>machines more easily, but I think I can work that out.

ExpanDrive is great for that.

>The bigger issue is all those times when you're at the command line of
>an ssh session and you need to edit a file, or a tool like git wants to
>invoke an editing session. It sounds like nobody yet has a good
>solution for that, which is disappointing. I guess I'll have to come
>up with something for that myself.

I'm sure lots of people on this list would be interested in a
solution. I suspect there is no general purpose solution due to
differences in servers and client setups.

I would be super interested if you can simplify the process from
the steps I gave. In short, you need to get BBEdit and file to
edit on same machine, and BBEdit is not going to run on the
remote server, so file needs to get copied to machine with
BBEdit, or BBEdit needs remote mounted volume to access the
file. The remote machine then needs to instruct BBEdit to open
the file to edit, and then *wait* for editing to finish.

It's all doable, but solutions I've seen (or created) are very fragile.

My current solution is (loosely speaking):

- copy path of file in remote session
$ expan connect remote-server
$ bbedit /Volumes/remote-server/<path-to-file>

If I'm doing lots of editing the above isn't too bad since I
only have to mount remote volume once.

Hmm, maybe the above steps could be scripted lots more easily
than the `scp` solution I used before.

OK, decided to give it another go. Script is attached. It is
still quite fragile.

- requires absolute path names for files to be edited
- there is no error checking
- there is no checking that expandrive volume has finished
mounting (or was even successful)
- needs ssh keys to be convenient (avoid entering password every time)
- needs firewall or port forwarding for bbedit host
- needs ExpanDrive installed and configured

Script is called like:

$ rbbedit.sh /home/charlie/site/index.html

The script could convert relative paths to absolute easily
enough. The error checking could be added easily, except for
checking that expandrive has completed; that might need to be a
remote (ssh) check for "path exists".
rbbedit.zip

Andrew B

unread,
Aug 31, 2014, 9:38:29 PM8/31/14
to bbe...@googlegroups.com
Thanks for the details... and no offence, but it seems pretty fragile. :)

I was thinking of running a daemon on login on the remote machine, passing it the IP of my BBEdit OSX box (perhaps in an SSH shell this can be derived automatically?). The OSX machine would run a daemon of its own listening for connections... ideally it could figure out how to use the mount command to connect to a file system on a remote machine when an edit request first arrived. Then a command would be written that talks to the local daemon, passing it edit requests and waits for a completion signal.

Source for the remote side would be open and portable to any posix system (hopefully).

Too ambitious?

Andrew B

unread,
Aug 31, 2014, 10:13:39 PM8/31/14
to bbe...@googlegroups.com
I've tried those as well, while better I still would prefer a "proper" text editor.

Charlie Garrison

unread,
Sep 1, 2014, 2:30:33 AM9/1/14
to bbe...@googlegroups.com
Good afternoon,

On 31/08/14 at 6:38 PM -0700, Andrew B
<andrew.e....@gmail.com> wrote:

>Too ambitious?

Don't know, but not sure how that is much better than using SSH
as the daemon. All the communication can already be done with
SSH, so why introduce another protocol into the mix?

The IP address of the BBEdit machine should be easy enough to
get from the current login session, and then just set an
environment variable that the script uses.

Pretty much all the limitations with script I attached earlier,
can be solved with additional coding to harden the script. Even
the requirement for ExpanDrive could be replaced with `scp` commands.

The script does require 'remote login' to be enabled on the
BBEdit machine, but I don't see that as any more of a burden
than a separate daemon for this purpose.

armin

unread,
Sep 1, 2014, 4:00:58 AM9/1/14
to bbe...@googlegroups.com
I don't know if this is the solution you are looking for:
I'm working on remote servers all the time using either XQuartz or iTerm.
In my .tcshrc I have an alias
      alias bb     'ssh armin@$REMOTEHOST bbedit "sftp://$USER@$HOST/$PWD/\!*"'
Using
    bb <filename>
the file opens in a  BBEdit window on my Mac.
Even
    bb <dirname>
opens a project window.
Works without any problems for me.

Andrew B

unread,
Sep 1, 2014, 7:12:52 PM9/1/14
to bbe...@googlegroups.com
I misunderstood your previous post -- your solution is better than I thought at first.  I will give it a go to see how it works in practice.  I agree that using an existing protocol & daemon is preferable (less work, if nothing else).  Usually I find that script-based solutions are fragile, and your comment to that effect made me suspicious.   :)

Ken Dubuc

unread,
Sep 2, 2014, 11:14:24 AM9/2/14
to bbe...@googlegroups.com
I do something similar.

First, my ssh is configured to perform RSA authentication when ssh-ing from my Linux host to my Mac, so that I don't need to be entering a password every time I want  to edit a file.

Second, my Linux host's local file system -- at least, the directories containing files I'm interested in editing -- is remotely-mounted on my Mac. So, for example, my Linux home directory at /home/username/ is mounted on the same path, /home/username on my Mac. (Fortunately, this doesn't obscure my Mac home directory, at /Users/username.) My office Mac uses NFS to remotely mount parts of the Linux host's file system. On my wandering MacBook, I use ExpanDrive to remotely mount parts of the Linux host's file system via sftp.

(Parenthetically, I find ExpanDrive mounts to be a bit fragile, especially if my laptop sleeps for a longish period.)

Then, in my Linux .bashrc -- I prefer the bash shell -- I define function bbedit:

  bbedit()
  {
      ssh ${SSH_CLIENT%% *} "cd $PWD && bbedit $@"
  }

Then, if I ssh to my Linux host from my Mac, executing "bbedit ..." on the Linux host command line behaves identically to doing it from the Mac command line.

Charlie Garrison

unread,
Sep 2, 2014, 1:50:42 PM9/2/14
to bbe...@googlegroups.com
Good morning,

On 1/09/14 at 4:12 PM -0700, Andrew B
<andrew.e....@gmail.com> wrote:

>Usually I find that script-based solutions are fragile, and
>your comment to that effect made me suspicious. :)

I don't agree that scripts are inherently fragile; it depends on
the coding. You might be surprised how many *programs* are
really scripts.

Anyway, this conversation got me thinking about the different
possibilities, and I decided to expand the script a bit. You can
find it here:

<https://github.com/cngarrison/rbbedit>

I also listened to armin:

On 1/09/14 at 1:00 AM -0700, armin <hein...@googlemail.com> wrote:

>alias bb 'ssh armin@$REMOTEHOST bbedit "sftp://$USER@$HOST/$PWD/\!*"'

The new script has different methods to copy files between
server and workstation. The default method is 'sftp', which uses
the above technique. The other methods are 'scp' and 'expan'.

Feedback and contributions are welcome.
Reply all
Reply to author
Forward
0 new messages