Skip to content

Instantly share code, notes, and snippets.

@casimir
Created September 9, 2016 14:21
Show Gist options
  • Save casimir/23c4e708d2b11d480c2c8b39555e430f to your computer and use it in GitHub Desktop.
Save casimir/23c4e708d2b11d480c2c8b39555e430f to your computer and use it in GitHub Desktop.
ERE → BRE
#!/bin/sh
# Check with the examples from the spec (http://vimdoc.sourceforge.net/htmldoc/options.html#modeline)
# ./test_re.sh 'vi:noai:sw=3 ts=6' '/\* vim: set ai tw=75: \*/' '# kak: se ft=sh'
old_parse() {
printf %s\\n "$1" | gsed -r \
-e 's/^(.+\s\w+:\s?(set?)?\s)//' \
-e 's/:?\s[^a-zA-Z0-9_=-]+$//' \
-e 's/:/ /g'
}
new_parse() {
printf %s\\n "$2" | $1 \
-e 's/^[^:]\{1,\}://' \
-e 's/[ \t]*set\{0,1\}[ \t]//' \
-e 's/:[^a-zA-Z0-9_=-]*$//' \
-e 's/:/ /g'
}
check() {
echo $(old_parse "$1")
echo $(new_parse sed "$1")
echo $(new_parse gsed "$1")
}
for arg in "$@"; do
printf '> "%s"\n' "$arg"
echo =====
check "$arg"
echo =====
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment