~kris/dots

srice

ref: b42b72dc2648499470b89418ac629e40f41d3149 srice/.local/bin/kwic -rwxr-xr-x 314 bytes
b42b72dc — Kris Yotam sb-battery: match macsmc-battery by type, add low-battery dunst alerts; xprofile: caps:super 2 months ago
                                                                                
1
2
3
4
5
6
7
8
#!/usr/bin/env bash
# kwic -- KWIC concordancer
# Usage: kwic <pattern> <file> [context_words]
pattern="${1:?Usage: kwic <pattern> <file> [context_words]}"
file="${2:?Provide a file}"
ctx="${3:-5}"
grep -oP "(\S+\s+){0,$ctx}\S*${pattern}\S*(\s+\S+){0,$ctx}" "$file" | \
    sed "s/${pattern}/\x1b[1;31m&\x1b[0m/g"