Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@HaleTom
Created October 4, 2016 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HaleTom/a793106d85cf7be1bdb873631a9e1553 to your computer and use it in GitHub Desktop.
Save HaleTom/a793106d85cf7be1bdb873631a9e1553 to your computer and use it in GitHub Desktop.
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