-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_keywords.sh
executable file
·19 lines (17 loc) · 929 Bytes
/
process_keywords.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
# Usage: ./process_keywords.sh duckscript/docs/sdk.md
LINE_HEADER='syntax match duckKeyword display contained'
# All commands are listed on a single line after the "Aliases" heading of each
# function in the SDK docs. `-A1` grabs the heading and one line after it (the
# aliases themselves)
grep -A1 Aliases $1 |
sort -u | # Sort and collect duplicates
grep -v 'Aliases' | # Remove the `#### Aliases` lines
grep -v '\-\-' | # Remove the `--` lines
tr '\n' ' ' | # Turn newlines into spaces
tr -d ',' | # Remove commas from commands with multiple aliases
fold -w60 -s | # Wrap to 60 columns
sed 's/ \{2,\}/ /g' | # Compress multiple spaces to one
sed 's/ *$//' | # Delete spaces at the end of a line
tr ' ' '|' | # Replace spaces with '|'
sed 's/^/'"${LINE_HEADER}"' "\\v<%(/' | sed 's/$/)>"/' # Add our header/trailer