[TxMt] [TextMate] Help With Ruby Command
Jackie Chappell
jmchappell at mac.com
Tue Oct 26 11:57:31 UTC 2004
On Mon, 25 Oct 2004 23:55:02 -0500 Kjell Olsen wrote:
> I can't make the date function work within the command - If I execute
> my script outside of textmate it works beautifully, but from within
> textmate I get:
>
> <code>
> date: illegal time format
> usage: date [-nu] [-r seconds] [+format]
> date [[[[[cc]yy]mm]dd]hh]mm[.ss]
> </code>
Timothy Martens' solution of using an external script which is then
called with a command works well, or -- if you'd prefer to keep it all
within TextMate, you could try something like:
ruby <<END
task_text = "$TM_SELECTED_TEXT"
task_text.gsub!("\[ \] ","[X] ")
print ""
from = File.basename("$TM_FILEPATH",".txt")
comp_time = Time.now
datestamp = comp_time.strftime("%d/%m/%Y at %H:%M")
File.open("/Users/me/completed.txt",'a'){|archive_file|
archive_file.puts
archive_file.puts "#{task_text} => in #{from} on #{datestamp}"
}
END
I ran into a similar problem, which I suspect in my case was down to
escaping the quotes in the format string wrongly. The double quotes to
form the Ruby string make this tricky. I decided to side-step the issue
slightly long-windedly by using Ruby's 'date' methods. Note also that
this code works on selected text: I have Standard in = selected text
and Standard out = Replace selected text. The selected task then gets
deleted from the original file and pasted in to the completed.txt file
with a checkbox ([X]).
I also put the date stamp on the same line as the text to make it
easier to grep for; when someone chases me about something I've done, I
can double-check when I did it ;-)
I'm a Ruby-newbie too, so I'm sure more experienced coders could make
it more efficient.
Jackie
--
Jackie Chappell
jmchappell at mac.com
More information about the textmate
mailing list