From 9c1224578330135406ddc9f461184ff1f6756c0c Mon Sep 17 00:00:00 2001 From: Adam Hovorka Date: Sun, 30 Sep 2018 20:36:27 -0600 Subject: Add some more random utilities/functions --- base.yaml | 5 ++++ base/nyan | 24 ++++++++++++++++++ base/pr-dups | 55 ++++++++++++++++++++++++++++++++++++++++ base/pr-passive | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ base/pr-weasel | 41 ++++++++++++++++++++++++++++++ base/proofread | 27 ++++++++++++++++++++ base/zsh/functions.zsh | 6 +++++ 7 files changed, 226 insertions(+) create mode 100755 base/nyan create mode 100755 base/pr-dups create mode 100755 base/pr-passive create mode 100755 base/pr-weasel create mode 100755 base/proofread diff --git a/base.yaml b/base.yaml index d4affd6..6c525df 100644 --- a/base.yaml +++ b/base.yaml @@ -11,6 +11,11 @@ ~/.ackrc: base/ackrc ~/.bin/cht.sh: base/cht.sh ~/.bin/dot: base/dot + ~/.bin/nyan: base/nyan + ~/.bin/pr-dups: base/pr-dups + ~/.bin/pr-passive: base/pr-passive + ~/.bin/pr-weasel: base/pr-weasel + ~/.bin/proofread: base/proofread ~/.bin/tldr: base/tldr ~/.capsesc: base/capsesc ~/.curlrc: base/curlrc diff --git a/base/nyan b/base/nyan new file mode 100755 index 0000000..5929327 --- /dev/null +++ b/base/nyan @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Print nyan cat +# https://github.com/steckel/Git-Nyan-Graph/blob/master/nyan.sh +# If you want big animated version: `telnet miku.acm.uiuc.edu` + +RED="$(tput setaf 1)" +GREEN="$(tput setaf 2)" +YELLOW="$(tput setaf 3)" +CYAN="$(tput setaf 6)" +WHITE="$(tput setaf 7)" +BOLD="$(tput bold)" +NOCOLOR="$(tput sgr0)" + +echo +echo -en $RED'-_-_-_-_-_-_-_' +echo -e $NOCOLOR$BOLD$WHITE',------,'$NOCOLOR +echo -en $YELLOW$WHIT'_-_-_-_-_-_-_-' +echo -e $NOCOLOR$BOLD$WHITE'| /\_/\\'$NOCOLOR +echo -en $GREEN'-_-_-_-_-_-_-' +echo -e $NOCOLOR$BOLD$WHITE'~|__( ^ .^)'$NOCOLOR +echo -en $CYAN'-_-_-_-_-_-_-' +echo -e $NOCOLOR$BOLD$WHITE'"" ""'$NOCOLOR +echo diff --git a/base/pr-dups b/base/pr-dups new file mode 100755 index 0000000..211ab64 --- /dev/null +++ b/base/pr-dups @@ -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 ...\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 () { + 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 ; +} diff --git a/base/pr-passive b/base/pr-passive new file mode 100755 index 0000000..e95c70c --- /dev/null +++ b/base/pr-passive @@ -0,0 +1,68 @@ +#!/usr/bin/env 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` ..." + exit +fi + +egrep -n -i --color \ + "\\b(am|are|were|being|is|been|was|be)\ +\\b[ ]*(\w+ed|($irregulars))\\b" $* + +exit $? diff --git a/base/pr-weasel b/base/pr-weasel new file mode 100755 index 0000000..052dacd --- /dev/null +++ b/base/pr-weasel @@ -0,0 +1,41 @@ +#!/usr/bin/env 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` ..." + exit +fi + +egrep -i -n --color "\\b($weasels)\\b" $* + +exit $? diff --git a/base/proofread b/base/proofread new file mode 100755 index 0000000..2db4382 --- /dev/null +++ b/base/proofread @@ -0,0 +1,27 @@ +#!/usr/bin/env 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` ..." + exit +fi + +header "Weasel words" +pr-weasel $1 +echo + +header "Passive voice" +pr-passive $1 +echo + +header "Duplicates" +pr-dups $1 diff --git a/base/zsh/functions.zsh b/base/zsh/functions.zsh index f705d28..db4271e 100644 --- a/base/zsh/functions.zsh +++ b/base/zsh/functions.zsh @@ -19,3 +19,9 @@ function trash { wttr() { curl -q -H "Accept-Language: ${LANG%_*}" wttr.in/"${1:-Pleasant Grove}\?${2:-0q}" } + +hex() { + emulate -L zsh + if [[ -n "$1" ]]; then printf "%X\n" $1 + else print 'Usage: hex '; fi +} -- cgit v1.2.3-70-g09d2