main dots / config / .local / bin / passive
xxwhirlpool  ·  2026-05-21
 1#!/usr/bin/env bash
 2#
 3# script to detect passive voice in a file
 4#
 5# inspired by the below blog post:
 6# https://matt.might.net/articles/shell-scripts-for-passive-voice-weasel-words-duplicates/
 7
 8# vars
 9passive_worddir="$HOME/.config/wordfiles"
10passive_wordfile="$passive_worddir/passive"
11
12# basic functions
13usage_help() {
14	echo "Usage: passive [OPTIONS]"
15	echo "Options: -f | -h"
16}
17
18die() {
19    printf "%s\n" "$1"
20    exit 1
21}
22
23# check if word file exists
24wordfile_check() {
25	[[ -f "$passive_wordfile" ]] || die "passive word file does not exist"
26}
27
28# cat the word file into a var
29words=$(wordfile_check && cat "$passive_wordfile")
30
31# do the thing; two options
32# "": stdinpaste
33# -f: read from file
34readfile() {
35	inputfile=$(gum file) || die "no file supplied"
36	gum_echo "passive voice found:"
37	grep -E -n -i --color "\\b(am|are|were|being|is|been|was|be)\ \\b[ ]*(\w+ed|($words))\\b" "$inputfile"
38}
39
40stdinpaste() {
41	inputtext=$(gum write --header "paste text here") || die "no text supplied"
42	gum_echo "passive voice found:"
43	echo "$inputtext" | grep -E -n -i --color "\\b(am|are|were|being|is|been|was|be)\ \\b[ ]*(\w+ed|($words))\\b"
44}
45
46# run script
47case "$1" in
48	"") stdinpaste;;
49	"-f") readfile;;
50	"-h") usage_help;;
51esac