Three shell scripts to improve your writing.

This commit is contained in:
Artem Sapegin 2013-02-08 15:33:43 +04:00
parent 4a526015d3
commit 9108b2dc1b
4 changed files with 195 additions and 0 deletions

55
bin/dups Executable file
View File

@ -0,0 +1,55 @@
#!/usr/bin/env perl
# Finds duplicate adjacent words.
# http://matt.might.net/articles/shell-scripts-for-passive-voice-weasel-words-duplicates/
use strict ;
my $DupCount = 0 ;
if (!@ARGV) {
print "Usage: dups <file> ...\n" ;
exit ;
}
while (1) {
my $FileName = shift @ARGV ;
# Exit code = number of duplicates found.
exit $DupCount if (!$FileName) ;
open FILE, $FileName or die $!;
my $LastWord = "" ;
my $LineNum = 0 ;
while (<FILE>) {
chomp ;
$LineNum ++ ;
my @words = split (/(\W+)/) ;
foreach my $word (@words) {
# Skip spaces:
next if $word =~ /^\s*$/ ;
# Skip punctuation:
if ($word =~ /^\W+$/) {
$LastWord = "" ;
next ;
}
# Found a dup?
if (lc($word) eq lc($LastWord)) {
print "$FileName:$LineNum $word\n" ;
$DupCount ++ ;
} # Thanks to Sean Cronin for tip on case.
# Mark this as the last word:
$LastWord = $word ;
}
}
close FILE ;
}

69
bin/passive Executable file
View File

@ -0,0 +1,69 @@
#!/bin/bash
# Abuse of the passive voice
# http://matt.might.net/articles/shell-scripts-for-passive-voice-weasel-words-duplicates/
irregulars="awoken|\
been|born|beat|\
become|begun|bent|\
beset|bet|bid|\
bidden|bound|bitten|\
bled|blown|broken|\
bred|brought|broadcast|\
built|burnt|burst|\
bought|cast|caught|\
chosen|clung|come|\
cost|crept|cut|\
dealt|dug|dived|\
done|drawn|dreamt|\
driven|drunk|eaten|fallen|\
fed|felt|fought|found|\
fit|fled|flung|flown|\
forbidden|forgotten|\
foregone|forgiven|\
forsaken|frozen|\
gotten|given|gone|\
ground|grown|hung|\
heard|hidden|hit|\
held|hurt|kept|knelt|\
knit|known|laid|led|\
leapt|learnt|left|\
lent|let|lain|lighted|\
lost|made|meant|met|\
misspelt|mistaken|mown|\
overcome|overdone|overtaken|\
overthrown|paid|pled|proven|\
put|quit|read|rid|ridden|\
rung|risen|run|sawn|said|\
seen|sought|sold|sent|\
set|sewn|shaken|shaven|\
shorn|shed|shone|shod|\
shot|shown|shrunk|shut|\
sung|sunk|sat|slept|\
slain|slid|slung|slit|\
smitten|sown|spoken|sped|\
spent|spilt|spun|spit|\
split|spread|sprung|stood|\
stolen|stuck|stung|stunk|\
stridden|struck|strung|\
striven|sworn|swept|\
swollen|swum|swung|taken|\
taught|torn|told|thought|\
thrived|thrown|thrust|\
trodden|understood|upheld|\
upset|woken|worn|woven|\
wed|wept|wound|won|\
withheld|withstood|wrung|\
written"
if [ "$1" = "" ]; then
echo "Usage: `basename $0` <file> ..."
exit
fi
egrep -n -i --color \
"\\b(am|are|were|being|is|been|was|be)\
\\b[ ]*(\w+ed|($irregulars))\\b" $*
exit $?

29
bin/proofread Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
# http://matt.might.net/articles/shell-scripts-for-passive-voice-weasel-words-duplicates/
# Common stuff
CYAN="$(tput setaf 6)"
UNDERLINE="$(tput sgr 0 1)"
NOCOLOR="$(tput sgr0)"
function header() {
echo -e "$UNDERLINE$CYAN$1$NOCOLOR"
}
if [ "$1" = "" ]; then
echo "Usage: `basename $0` <file> ..."
exit
fi
header "Weasel words"
weasel $1
echo
header "Passive voice"
passive $1
echo
header "Duplicates"
dups $1

42
bin/weasel Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash
# Weasel words
# http://matt.might.net/articles/shell-scripts-for-passive-voice-weasel-words-duplicates/
weasels="many|various|very|fairly|several|extremely\
|exceedingly|quite|remarkably|few|surprisingly\
|mostly|largely|huge|tiny|((are|is) a number)\
|excellent|interestingly|significantly\
|substantially|clearly|vast|relatively|completely"
wordfile=""
# Check for an alternate weasel file
if [ -f $HOME/etc/words/weasels ]; then
wordfile="$HOME/etc/words/weasels"
fi
if [ -f $WORDSDIR/weasels ]; then
wordfile="$WORDSDIR/weasels"
fi
if [ -f words/weasels ]; then
wordfile="words/weasels"
fi
if [ ! "$wordfile" = "" ]; then
weasels="xyzabc123";
for w in `cat $wordfile`; do
weasels="$weasels|$w"
done
fi
if [ "$1" = "" ]; then
echo "Usage: `basename $0` <file> ..."
exit
fi
egrep -i -n --color "\\b($weasels)\\b" $*
exit $?