On Mar 2, 2005, at 8:31 PM, Peter N Lewis wrote:
This has been mentioned a few times, but of course TextWrangler/BBEdit both support Edit via FTP/SFTP, so presuming you are SSHing to your target machine, then you can easily edit remote files with TextWrangler/BBEdit.

For example, on the target machine while logged in via ssh, you can do this:

ssh [EMAIL PROTECTED] bbedit sftp://[EMAIL PROTECTED]/perl/Peter/Tools.pm

I'll leave as an exercise to the perl hacker as to how to have to set up[ an alias and script to do this by typing

rbbedit Tools.pm

OK, here are the results of my exercise, based mostly on code sent directly from Peter (thanks), with a few minor modifications. Save as rbbedit somewhere in your $PATH on a remote Unix box, ssh into the box from your Mac and type:


        rbbedit <filename>

to open the file via SFTP in BBEdit on your Mac. Or

        rbbedit <dirname>

to open an SFTP directory browser on you Mac. It even works with pipes, like:

        ls -al | rbbedit

Note: you must have ssh access to your Mac from the Unix box for it to work. With the appropriate KeyChain entries and/or ~/.ssh/authorized_keys I was even able to get it to work without prompting me for passwords.

Enjoy ... and many thanks to Peter for the idea and much of the code ...

        Ray

P.S. Too bad the bbdiff command-line tool doesn't handle remote files ...

---------------------------------------------------

#!/usr/bin/perl -w

use strict;
use File::Spec;

my $default_bb_host = 'mymac.somedomain.org';
my $user = $ENV{USER};
my $host = $ENV{HOSTNAME} || $ENV{HOST};
my $ssh_client = $ENV{SSH_CLIENT} || $ENV{SSH2_CLIENT};
($ssh_client) = $ssh_client =~ /(\d+\.\d+\.\d+\.\d+)/;
my $bb_host = $ENV{REMOTEHOST} || $ssh_client || $default_bb_host;

open_in_bbedit(@ARGV);

sub open_in_bbedit {
    my @urls;
    while (my $file = shift @_) {
        $file = File::Spec->rel2abs( $file );
        die "Path with colon! $file"    if $file =~ /:/;
        die "Does not exist: $file\n"   unless -r $file;
        if (-d $file) {
            $file .= '/';
        } else {
            warn "File is read only\n"  unless -w $file;
        }
        push @urls, "sftp://[EMAIL PROTECTED]/$file";
    }

    my @cmd = (
        'ssh',
        $bb_host,
        'bbedit',
        @urls,
    );
    print "@cmd\n";
    system( @cmd );
}

1;



Reply via email to