[TxMt] Feature request: "see" like SubEthaEdit
Eric Hsu
erichsu at math.sfsu.edu
Fri Jan 14 19:28:46 UTC 2005
1. I have appended a shell script that launches TM and allows piped
input. I did not write the script; in fact, I merely found it in my
~/bin directory and thought that it came with the standard TM
install. The -c option lets you create a new file.
It does lack the crucial 'don't quit until editing is done' feature.
Here are three kludges I can think of to get that feature. Given a
-wait flag:
a. add a block at the end of the script that creates a $TM_FILE.lock
in the same directory and checks every N seconds for the .lock file.
When it's gone, quit the script. Then create a command that saves
current file and deletes the .lock file. Finally, write a little
macro that saves, closes the window and runs the 'delete .lock'
command.
In a future version of TM that triggers scripts/commands on events,
one can avoid the command and macro, and have 'Close Window' trigger
the deletion of the lock file.
b. have the shell script loop and check for changes to the
modification date on the file. Unfortunately, that means it will quit
on the first save. But you don't need any fiddling with macros and
commands.
c. call the Textmate Service from a (different) shell script. The TM
Service definitely blocks whatever app calls it. In other contexts
this might be a bug, but here it's great. However, I don't know how
to pipe text to a Cocoa Service from the command line. This may be
rather hard. Any ideas?
- Eric
---
#!/bin/sh
# Originally written by Rick Gardner (rick.gardner at mac.com)
# and Kevin Ballard (kevin at sb.org)
# Modified to work with TextMate by Andrew Ellis aellis at gmx.net
# 10-11-2004
OPEN="open -a TextMate"
CREATE="touch"
USAGE="usage: tm [-ch] filename [filename ...]"
CREATE_FILE=0
while getopts ch FLAG; do
case $FLAG in
c) CREATE_FILE=1;;
h|\?) echo $USAGE; exit 1;;
esac
done
shift $(($OPTIND - 1))
# are we dealing with a filename or are we using stdin?
if (( $# == 0 )); then
if [ ! -t 0 ]; then
exec 6<&0
exec 7>&1
prefix=/tmp/tm
suffix=$(date +%s) # The "+%s" option to 'date' is
GNU-specific.
filename=$prefix.$suffix
$CREATE $filename
exec > $filename
while read a1
do
echo $a1
done
open -a TextMate.app $filename
exec 0<&6 6<&-
exec 1<&7 7<&-
else
if [ ! -z ${1} ]; then
$CREATE ${1}
$OPEN ${1}
else
$OPEN
fi
fi
else
# iterate over the files
for filename; do
# create the file if requested
if (( $CREATE_FILE )); then
if [[ -f $filename ]]; then
echo "File \`$filename' already exists."
fi
$CREATE $filename
fi
if [[ -e $filename ]]; then # now also
opens directories
$OPEN "$filename"
else
echo "File \`$filename' does not exist."
fi
done
fi
More information about the textmate
mailing list