-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
504777b
commit 7e0c77b
Showing
1 changed file
with
22 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env nu | ||
|
||
word=$1 | ||
length=${#word} | ||
firstLetters=${word:0:1} | ||
# Find look alikes for a word | ||
def main [ | ||
word # Word to impersonate | ||
--margin = 3 # Lower = more similar, higher = less similar | ||
] { | ||
let letters = $word | split chars | ||
let length = $letters | length | ||
let firstLetters = $letters | first | ||
|
||
cat ~/scripts/words.txt | \ | ||
sed -n "/^${firstLetters}.*/p" | \ | ||
awk "{ if (length(\$0) < ${length} + 3 && length(\$0) > ${length} - 3) print }" | \ | ||
while IFS= read -r line; do | ||
if (($(levenshtein $line $word) < 3)); then | ||
echo "$line"; | ||
fi | ||
done | ||
open ~/scripts/words.txt | ||
| lines | ||
| where (str starts-with $firstLetters) | ||
| where ($it | split chars | length | $in < ($length + $margin) and $in > ($length - $margin)) | ||
| each { | ||
{ | ||
word: $in | ||
distance: ($in | str distance $word) | ||
} | ||
} | ||
| where distance < $margin | ||
| sort-by distance | ||
} |