Update vim's ":help compatible" table from source code extract
#!/bin/bash -eu | |
table_to_update=./compatible_table | |
source_extract=./option_extract | |
function get_decorated_options { | |
# option_extract > while read -r option; | |
while read -r line; do | |
name=$(printf %s "$line" | sed -rn 's/^\s*\{\s*"(\w+).*/\1/p') | |
# Get decoration | |
if [[ $line =~ 'P_VI_DEF' ]]; then | |
if [[ $line =~ 'P_VIM' ]]; then | |
decoration='+' | |
else | |
decoration='XXXXXX' # Shouldn't happen, means bad input | |
fi | |
elif [[ $line =~ 'P_VIM' ]]; then | |
decoration='\*' # Prevent shell expansion in 'set' | |
else | |
decoration='-' | |
fi | |
printf '%s '%s'\n' "$name" "$decoration" | |
done < "$source_extract" | |
} | |
# Clear out the current character flag column to check for options | |
# which should not be listed - an 'X' in final output | |
sed -r "s/^(\s*'\w+'\t+)[-+* ]/\\1X/" -i "$table_to_update" | |
# Process list of <option> <decoration> | |
get_decorated_options | | |
while read -r decorated_option; do | |
set $decorated_option # shellcheck disable=SC2086 | |
name="$1"; decoration="$2" | |
# Add missing entries to table | |
# grep -q "'$name'" "$table_to_update" | |
# if [[ ! $? ]]; then | |
if ! grep -q "'$name'" "$table_to_update"; then | |
printf "\t'%s'\t \t\t\n" "$name" >> "$table_to_update" | |
fi | |
sed -r "s/^(\s*'$name'\t+)[-+* X]/\\1$decoration/" -i "$table_to_update" | |
done | |
sort -o "$table_to_update" "$table_to_update" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment