Hi, Thanks for the previous help. I'm a little chagrined that they seemed obvious questions. I had looked for answers... honest. :)
Anyway, I've got another use case that I could use some help with. I often ssh into another unix box, and occasionally need to edit a file while I'm there. With bbedit, I had a script that would ssh back into my mac and then open the remote file on the unix box. I'm trying to replicate that with TextMate. The closest I've found in the mailing list is this:
http://comox.textdrive.com/pipermail/textmate/2006-February/008384.html
My version is as follows. On the remote box I have a script called 'mate':
----- #! /bin/sh
# Make sure we have the full path to the file if echo $1 | egrep ^/ - > /dev/null ; then path=$1 ; else path=`pwd`/$1 ; fi
HOST=`hostname`
echo Opening $path on ${SSH_CLIENT%% *}
ssh willu@${SSH_CLIENT%% *} remoteOpen ${USER} ${HOST} "$path" -----
On my Mac I have this script called 'remoteOpen':
----- #!/bin/sh
remUser=$1 remHost=$2 remPath=$3
remBase=`basename $remPath` remDir=`dirname $remPath`
tempDir=`mktemp -d` || exit 1
localfile="${tempDir}/scp:${remHost}:${remBase}" localBackup="${tempDir}/backup"
remLoc="${remUser}@${remHost}:${remPath}"
echo "${remLoc}" > ${tempDir}/remLoc
scp -Bpq "${remLoc}" "${localfile}" && cp "${localfile}" $ {localBackup} && osasc ript -e "tell app "Terminal" to do shell script "mate -w $ {localfile}""
if ! cmp -s "${localfile}" ${localBackup} ; then scp -Bpq "${localfile}" "${remLoc}" fi
rm -rf ${tempDir} -----
I then have the following command for use within TextMate (instead of the normal 'save'):
Save the current file then: ----- if [[ ${TM_FILEPATH} == */scp:* ]] ; then # this is an scp file # it has been saved by the time we get here # now just extract its remote name and scp it back localDir=`dirname $TM_FILEPATH` remLoc=`cat ${localDir}/remLoc` scp -Bpq "$TM_FILEPATH" "${remLoc}" && cp "$TM_FILEPATH" "$ {localDir}/backup" fi -----
This setup saves a backup of the remote version locally. If the local copy gets saved with the special command while you're editing, and the data is scp'd back to the other host, then the backup is updated. Otherwise, the difference is detected and the data is scp'd back to the remote box when the window is closed.
Current issues:
i) Most importantly, the 'mate' command doesn't work from a remote shell. This leads to the whole osascript workaround. Unfortunately, while Terminal is running a script it just queues up all the input to its other windows and waits for the script to end. This makes the current setup significantly less useful than the same setup using bbedit (where the 'bbedit' command does work from a remote terminal).
ii) It would be nice if there was a way to tell textmate 'run this script when you write to that file'. Basically, make the 'mate' command have an equivalent to the ODB Editor Suite of Apple Events. I imagine some extra options like this:
--title WindowTitle Start editing the new file with this window title instead of the file name as window title --onsave scriptPath When the file is saved, this script is run with the path to the file as an argument --onclose scriptPath When the file is closed (or Save As... is used to detach from the original file), this script is run with the path of the file as an argument
and perhaps a final option:
--on-reopen scriptPath Data This is a command line option that takes two arguments. If this file re-opened from the 'Open Recent >' menu then the script 'scriptPath' is run with 'Data' as an argument to get the path of the file to open.
This set of options would allow third parties to implement the much-requested 'sftp' feature, as well as any other file access method they wanted to.
Cheers,
Will :-}
P.S. I know - just use transmit or Cyberduck. The problem is that they require me to connect from the mac. I could modify my 'remoteOpen' script to use them instead of scp, and that would solve the 'detecting save' problem (point ii), but it wouldn't solve the worst problem, point i.