Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Scripts to manage text quote levels and wrapping UNIX
If you use webmail, you know that as you reply to messages the quoting will often get messed up with line wrapping. I was looking for a simple solution to handle this, and all I found were programs that did this plus a lot more, and they were shareware. So I wrote a shell script that will do the rewrap, unwrap, increase the quote level, and decrease the quote level. It works by having a parameter passed to it in the following manner:

change_quote.sh increase -- this will rewrap the text on the clipboard and add an additional ">" to the beginning of each new line. The full usage is as follows:
change_quote.sh (increase|decrease|rewrap|unwrap)
The package contains five scripts: one that does all the work, and four others that simply call the script with the appropriate parameter. I put the collection in ~/Library/Scripts, and access it from the system-wide Scripts menu. It works for any text on the clipboard, and copies the resultant changes to the clipboard.

[robg adds: I have mirrored the scripts here on macosxhints.com. You can read a bit more about the scripts, and potentially find updated versions, in this post on the author's blog.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[6,163 views]  

Scripts to manage text quote levels and wrapping | 2 comments | Create New Account
Click here to return to the 'Scripts to manage text quote levels and wrapping' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
quoter.pl - another way
Authored by: kholburn on Jun 19, '08 04:08:00AM
I tried this program and didn't like it because it quoted everything at the same level rather than maintaining the quote level of each paragraph separately.

I decided to write a perl script "quoter.pl" to wrap and unwrap the way I liked. Here it is. It's too long and complex to put the script up on a page. It's GPL so you can copy and adjust as you like.

The most useful commands I find are fix, +fix (increase and fix), -fix, unwrap, +unwrap.

unwrap: Sometimes I want to take a text email and convert it to html and keep the quotes but remove the wrapping. So this command unwraps the text into paragraphs with the quote marks for the original level at the start of each paragraph.

fix: In addition I discovered an interesting perl module called Text::Autoformat which can actually fix text that has been wrapped and quoted several times and has got pretty messed up. The best way to use this is by itself (fix) or increase quote level first and then run autoformat (+fix). You can read about it here.

The tarball of my script includes the perl Text::Autoformat and Text::Reform modules. You could get them instead from CPAN or using any package system:
macports :
sudo port install p5-text-autoformat
or fink :
sudo aptget install text-autoformat-pm
You use the script the same way but it has several additional commands:
increase or "+"
decrease or "-"
unwrap - unwraps the text but each para starts with the quote character.
wrap - simple wrap using the installed perl library Text::Wrap
fmt - simple wrap using the installed unix command fmt
fix - complex multi-quoted text reformat

it has a number of compound commands:
rewrap = unwrap, wrap
refmt = unwrap, fmt

You can add + or - in front of any command which does an increase or decrease then the command. This works on +unwrap, +wrap, +fmt, +fix, +rewrap, +refmt.

You can put multiple commands which will be executed in sequence. fix is best used by itself, it doesn't do well on unwrapped text so the sequence "unwrap fix" isn't much use.
You can make a symbolic link to the script with a command name an it will execute the command. Some examples are included in the tar file.


[ Reply to This | # ]
Scripts to manage text quote levels and wrapping
Authored by: chueewowee on Aug 12, '08 09:26:56AM

Hi kholburn,

many thanks for your kind offering here, which i just stumbled upon and tested with fix and unwrap (which took mue all of ten minutes, including macport installations).
They're great tools, just what i ordered, and so accessible, from a bash alias. Now I only have to build an applescript to copy and switch, call script, and switch back and paste.

John



[ Reply to This | # ]