~kris/dots

srice

ref: f5fc91419850ee5f2652bdce0dcc214de18b4a22 srice/.local/bin/kwic -rwxr-xr-x 314 bytes
f5fc9141 — Kris Yotam add wallpapermenu script (was untracked); auto-detect output so cw works on any machine 3 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"