Re: LSX Command > Add text to file
"Ace McKool" <[email protected]> Tue, 11 Dec 2007 11:45:00 -0800
| Newsgroups | gmane.comp.windows.shells.litestep |
|---|---|
| Message-ID | <[email protected]> |
Thanks for this! This is my first time with Lua, so I have a few follow-up questions: 1. Do I need any of the Lua packages to run this? e.g. textedit? 2. How do I confirm the path to the blah.txt file? I tried: OUTFILE = 'c:\\blah.txt" but that didn't seem to work. Thank you very much for this though, looks pretty cool. On Dec 11, 2007 6:32 AM, Jochen Ritzel <[email protected]> wrote: > Some Lua: > [code, copy to some file and *luascriptfile it] > -- config this. > local clienttracker = { > OUTFILE = 'blah.txt', > -- if you want some formatting, you can set that here > INFORMAT = '%s*([^>]*) > (.*)%s*', -- the input string is parsed with > this pattern > OUTFORMAT = '%s | %s', -- and formatted with this pattern > afterwards ... you could add tabs ( \t ) here ... > TIMESTAMP = true, > TIMEFORMAT = '%c', --see > http://www.thinkage.ca/english/gcos/expl/c/lib/strfti.html > ERROR = function(self, msg ) -- if an error occures, it is > reported with this function > --lslua.message_box("An Error occured: ".. msg, "Error!" ) > print( "An Error occured:", msg ) > end > } > > -- admire this. > function clienttracker:_format( client, text ) > local s = self.OUTFORMAT:format( client, text) > if self.TIMESTAMP then > return ('%s: %s\n'):format( os.date( self.TIMEFORMAT), s ) > else > return s > end > end > function clienttracker:parse( s ) > local ok, client, text = pcall( string.match, s, self.INFORMAT ) > if not ok then return self:ERROR( client ) end > ok, text = pcall( self.add, self, client, text ) > if not ok then return self:ERROR( text ) end > end > function clienttracker:add( client, text ) > local fp = io.open(self.OUTFILE, "a") > fp:write( self:_format( client, text ) ) > fp:close() > end > > -- rename this. > function bang_tracker( s ) > return clienttracker:parse( s ) > end > [/code] > > Usage: > !tracker "You > I wrote you some code." > > Should be very easy to understand and expand ... hf > > --thc4k > > > On Mon, 10 Dec 2007 20:22:39 +0100, Ace McKool <[email protected]> > wrote: > > > Hi Everyone, > > > > I'm trying to track my time at work. I was hoping to use LSXCommand > > (plus > > any needed modules) to do something like: > > > > ?tracker "Some Client > I did this for them" > > > > And it would simply write the string to a file and add a timestamp if > > possible. > > > > Anybody have any recommendations on how to get this started? Thanks! > > > > --------------------------------------------------------------------- > Can't Unsubscribe? Check http://desktopian.org/listunsub.html > LS List Homepage: http://wuzzle.org/list/litestep.php > Get the LS FAQ: http://lsfaq.shellfront.org > >