[TxMt] Help with simple command
Allan Odgaard
throw-away-1 at macromates.com
Wed May 10 09:58:15 UTC 2006
On 10/5/2006, at 3:19, Oliver Taylor wrote:
> 1. Take the current line number, divide my 38 and display the result
> as a tooltip that reads: Aprox. Page-Count for Current Line: XX
> 2. Take the total number of lines in the document, divide my 38 and
> display the result as a tooltip that reads: Aprox. Page-Count for
> Document: XX
As a shell script (i.e. just paste in body of command):
echo "Aprox. page #$(( (TM_LINE_NUMBER+37) / 38 ))"
echo "Aprox. total pages $(( `wc -l` / 38 + 1 ))"
Basically $((…)) allows you to do math in the shell. `…` runs a
command, in this case, it runs `wc -l` which is word count (but with -
l, gives number of lines).
The command should have Input set to Entire Document.
I add 37 to the current line number, since the shell truncates the
value, and I assume you want it rounded up. I.e. line 1-37 should say
page #1.
As for total number of pages, I just add 1 to the result, since `wc`
gives a zero-based number, so I would have to add one to make it one-
based, and then 37 to round up (1 + 37 = 38).
More information about the textmate
mailing list