Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Edit remote files using local copy of BBEdit via sftp UNIX
I often use the BBEdit command line tool to quickly open and edit local files from the command line. In fact, I use it so much that I would find myself trying to use it while logged into remote machines via SSH:
[ben@remoteServer123 ~]$ bbedit  MyLargePythonScript.py
bbedit: Command not found.
If I wanted to use BBEdit, I would have to use its clunky (IMHO) SFTP/FTP interface to navigate to the file and open it. Finally, I got around to putting together a simple alias that will tell your local copy of BBEdit to open the remote file via sftp. Simpy add this alias to your .cshrc file (or equivalent) on the remote host:
alias bbedit 'ssh ben@$REMOTEHOST bbedit "sftp://$USER@$HOST/$PWD/!:1"'
Unless your name is Ben, you'll have to replace ben with your own user name on your local Mac, of course, but otherwise it works on the various flavors of unix I log into remotely. And of course, you have to have Remote Login enabled in the Sharing panel of System Preferences.

Now when I try to open that file:
[ben@remoteServer123 ~]$ bbedit MyLargePythonScript.py 
ben@localMacHostName's password: 
I enter my password, and then after a second or two, BBEdit opens displaying my file. If you have a bookmark set up for the remote host in BBEdit, BBEdit won't even ask for a password.

If you have problems with name resolution, then instead of using REMOTEHOST and HOST, you can substitute SSH_CLIENT_ADDRESS and SSH_HOST_ADDRESS, respectively. The following shell commands should be added to your .cshrc file on the remote host. This is a clunky workaround, and you will likely see error messages every time you log into those machines without using SSH.
set SSH_CLIENT_ADDRESS = `echo $SSH_CONNECTION | cut -f1 -d" "`
set SSH_HOST_ADDRESS = `echo $SSH_CONNECTION | cut -f3 -d" "`
[robg adds: I haven't tested this one...]
    •    
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
 
[12,468 views]  

Edit remote files using local copy of BBEdit via sftp | 16 comments | Create New Account
Click here to return to the 'Edit remote files using local copy of BBEdit via sftp' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Edit remote files using local copy of BBEdit via sftp
Authored by: xSmurf on Aug 16, '05 11:07:50AM
Leet! I've wanted something like this for a while now!
Sadly I can't seam to make it work. In my .bash_profile I have:
alias rbbedit='ssh 192.168.2.1 bbedit "sftp://192.168.2.2/!:1"'
When I try it out, it does connect as it asks for a password... but no go :/

Fripouille:~ xSmurf$ echo "lol" > ~/test.txt
Fripouille:~ xSmurf$ rbbedit test.txt 
Password:
Sorry, the bbedit tool has experienced an error: -43
    File not found. Use -c to create a file for editing.
What ever I give it for an argument it doesn't see the file even if I know it's there! Help would be much appreciated!

P.S. I also tried without the alias just to see if it wasn't receiving the arg. properly but it doesn't seam to be the case as the error still comes up.

---
PM G4 DP 800 / 1.25gb / 120Gb+80Gb / CD/DVD±RW/RAM/DL
- The only APP Smurf

[ Reply to This | # ]

Edit remote files using local copy of BBEdit via sftp
Authored by: bimtob on Aug 16, '05 08:54:59PM
Try:
alias rbbedit='ssh 192.168.2.1 bbedit "sftp://192.168.2.2/$PWD/!:1"'
The $PWD is replaced with the path to your current directory (i.e. /Users/xSmurf/).

Or you can leave it like you have it and use the full path to the file you want to edit.
Like so:
Fripouille:~ xSmurf$ rbbedit /Users/xSmurf/test.txt 


[ Reply to This | # ]
Edit remote files using local copy of BBEdit via sftp
Authored by: xSmurf on Aug 16, '05 10:01:19PM

Ho, for some reason I didn't think of the "pwd" command and had password in mind! So I placed it back... no go :/ Same error

---
PM G4 DP 800 / 1.25gb / 120Gb+80Gb / CD/DVD±RW/RAM/DL
- The only APP Smurf



[ Reply to This | # ]
Edit remote files using local copy of BBEdit via sftp
Authored by: xSmurf on Aug 16, '05 10:18:25PM

P.S. I did also try escaping the '!'... no go :/

---
PM G4 DP 800 / 1.25gb / 120Gb+80Gb / CD/DVD±RW/RAM/DL
- The only APP Smurf



[ Reply to This | # ]
Edit remote files using local copy of BBEdit via sftp
Authored by: bimtob on Aug 17, '05 11:29:42AM

Check lukemelia's comment. Looks like a bash thing.



[ Reply to This | # ]
Re: Edit remote files using local copy of BBEdit via sftp
Authored by: szedula on Aug 16, '05 11:09:31AM
On OpenBSD I needed to change:
alias bbedit 'ssh ben@$REMOTEHOST bbedit "sftp://$USER@$HOST/$PWD/!:1"'
to:
alias bbedit 'ssh ben@$REMOTEHOST bbedit "sftp://$USER@$HOST/$PWD/\!:1"'
Will this be the same in other UNIX systems?

Also, the BBEdit bookmark needs to have the numeric address in the "Server" field. The first time I tried this I typed the "name" of the system so I still needed to type in the password for the OpenBSD system.

[ Reply to This | # ]
Re: Edit remote files using local copy of BBEdit via sftp
Authored by: ashill on Aug 16, '05 02:35:12PM

Yes, you have to escape the exclamation point when you define the alias on any machine (including on Macs).



[ Reply to This | # ]
Edit remote files using local copy of BBEdit via sftp
Authored by: miggins on Aug 17, '05 12:09:11AM
I had to write it as a script using bash on Debian sarge:

#!/bin/sh
f=$1
ssh user@mac.host edit "sftp://$USER@$HOSTNAME/$PWD/$f"
Change the user@mac.host to your needs. And I'm using TextWrangler so that uses the edit command rather than bbedit.

[ Reply to This | # ]
Here's a solution for bash
Authored by: lukemelia on Aug 17, '05 12:11:36AM
Took me a little fidgeting, but I figured out how to adapt this to work under bash. I added the following to my .bash_profile file:
 
SSH_CLIENT_ADDRESS=`echo $SSH_CONNECTION | cut -f1 -d" "`
export SSH_CLIENT_ADDRESS

SSH_HOST_ADDRESS=`echo $SSH_CONNECTION | cut -f3 -d" "`
export SSH_HOST_ADDRESS

bbedit() {
	ssh lmelia@$SSH_CLIENT_ADDRESS bbedit \"sftp://$USER@$SSH_HOST_ADDRESS/$PWD/"$@"\"
}
Thanks for the hint! -Luke

[ Reply to This | # ]
Here's a solution for bash
Authored by: geordie on Mar 04, '11 06:32:47PM
I prefer to be able to edit files that are not just in my current path. Therefore I get the absolute path to the file instead of using: that way I can do things like "bbedit /etc/httpd/httpd.conf"
bbedit() {
FILEPATH=$(readlink -f "$@")
ssh user@$SSH_CLIENT_ADDRESS bbedit \"sftp:$USER@$SSH_HOST_ADDRESS/"${FILEPATH}"\"
}


[ Reply to This | # ]
open stuff remotely
Authored by: kholburn on Aug 17, '05 04:55:38AM
I tried this using something similar:

 ssh mydesktop open -a TextWrangler2.0.app sftp://fred@remote/~/filename
works quite well.

Unfortunately many of the machiens I want to talk to don't seem to have SSH_CONNECTION. They have SSH_CLIENT but that doesn't have the remote machiens IP number. So I'll have to add stuff to my login scripts.

Nice idea though.



[ Reply to This | # ]
Same issue here: only SSH_CLIENT is defined
Authored by: sjonke on Aug 17, '05 11:41:31AM

From it we can get the Mac's address, but not the host. Is there a unix command that will return the address of the host?

---
--- What?



[ Reply to This | # ]
Same issue here: only SSH_CLIENT is defined
Authored by: baba on Aug 17, '05 10:18:06PM
This depends on the type of *nix.
I found that our Solaris servers provided neither REMOTEHOST nor any SSH environment variable. *Very annoying*
Try 'printenv' to see what's available, or better:
printenv | sort | more

This may work, too:
SSH_HOST_ADDRESS=`host $HOST | cut -f4 -d" "`
or
SSH_HOST_ADDRESS=`host $HOSTNAME | cut -f4 -d" "`
depending on which (if either) is available.

This is the best hint I've seen in a very long time. I've been making do with BBOpen (using plain ftp and an ssh tunnel) for several years. This is much more sensible. Thanks.

[ Reply to This | # ]
Same issue here: only SSH_CLIENT is defined
Authored by: luomat on Aug 25, '05 08:41:04PM

This is what I use to get REMOTEHOST

REMOTEHOST=`who am i | awk '{print $NF}' | tr -d '(|)'`



[ Reply to This | # ]
Edit remote files using local copy of BBEdit via sftp
Authored by: xSmurf on Sep 11, '05 01:16:21PM

I finally understood why it didn't work. BBedit 7.X CLI tool does not support sftp...
I upgraded to a later version (8.X) and BAM it works :D
Maybe this will help someone else...

---
Free iPods, now in Canada to! Get yours : http://tinyurl.com/75yta

PM G4 DP 800 / 1.25gb / 120Gb+80Gb / CD/DVD±RW/RAM/DL
- The only APP Smurf



[ Reply to This | # ]
Edit remote files using local copy of BBEdit via sftp
Authored by: simplynutty on Jul 29, '10 08:33:52AM

This hint is freakin' awesome! While I love BBEdit, I'm faster at navigating and opening files via terminal. Now I can have both!



[ Reply to This | # ]