#!/bin/tcsh -f #(ie run the tshell on this but don't read the .cshrc or .tcshrc) echo version = 1.12 of fb 2011 Apr 14 # 2011 Apr 14, 1.12: format before removing cr to fuse paragraphs # 2011 Apr 09, 1.11: timestamp in /tmp file # 2011 May 11, 1.10: convert ^M to \n # 2011 Apr 23, 1.08: pbcopy and pbpaste for Linux # 2011 Apr 23, 1.07: use $EDITOR for editor # 2011 Apr 04, 1.06: More quiet # 2011 Mar 30, 1.05: fuse say, background both # 2011 Mar 29, 1.04: fix documentation # 2011 Mar 24, 1.03: If no cr in input, then remove cr in final result! # 2011 Feb 22, 1.02: rename from fixbuffer to fb # 2010 Jan 03, 1.01: Tidy up # 2009 Nov 9, 1.00: origin echo "fb: fix buffer" echo "Dump the current buffer into a file, allow user to edit it and" echo "return the file to the buffer. See also the buffer script." echo "If there are no newlines in the input, none are put in the output." echo "If there are arguments on the input line, remove newlines from the output." echo 'If there is an environmental variable $EDITOR, that indicates the' echo 'editor to use, otherwise vim is called.' echo '' echo 'The temporary file has a time stamp so that fb can be called' echo 'several times simultaneously in different terminals.' echo 'This allows the user to essentially hold multiple buffers.' echo 'When one wants to release the buffer to the cut/paste buffer,' echo 'just quite the editing window.' echo '' echo 'This script depends on Mac OS X pbpaste and pbcopy.' echo 'However, you can implement them in Linux according to' echo 'http://whereswalden.com/2009/10/23/pbcopy-and-pbpaste-for-linux/' echo '' echo 'dependencies: pbpaste, pbcopy, tomdate' # Thomas D. Schneider, Ph.D. # National Institutes of Health # National Cancer Institute # Gene Regulation and Chromosome Biology Laboratory # Molecular Information Theory Group # Frederick, Maryland 21702-1201 # http://alum.mit.edu/www/toms (permanent) set tmp1 = /tmp/`whoami`-`tomdate`.fixbuffer if !($?EDITOR) then set EDITOR = vim endif # grab the current buffer; # convert contro-Ms to cr pbpaste |\ tr ' ' '\n' |\ cat > $tmp1 # detect carriage returns # pbpaste |tr -d '[:print:]' | wc -c # gave 0 for buffer with no cr # if (`pbpaste |tr -d '[:print:]' | wc -c` == 0) then if (`pbpaste |tr -dc '\n' | wc -c` == 0) then set carriagereturns = 0 else set carriagereturns = 1 endif # echo $carriagereturns carriagereturns # cat $tmp1 # remove carriage returns if there is an argument set s = "$#argv arguments. I will " if ($#argv == 1) then set carriagereturns = 0 endif if ($carriagereturns) then #say "$s keep CRs" & #say "CR" & else #say "$s remove CRs" & #say "no CR" & endif $EDITOR $tmp1 if ($carriagereturns) then cat $tmp1 | pbcopy echo "Carriage returns retained" else cat $tmp1 | fmt -5000 | tr -d '\n' | pbcopy echo "Carriage returns removed" endif exit ******************************************************************************** 2011 Apr 27 The following line does a really weird thing. set masteraltstrings = /tmp/`whoami`.masteraltstrings I picked it up in the buffer. the result was: et masteraltstrings = /tmp/`whoami`.masteraltstrings i I can't reproduce it now! ********************************************************************************