#!/usr/bin/env ruby # Generate a reference sheet for Kakoune's normal mode # Use: ./kakmap.rb ../src/normal.cc require 'markaby' # Relies on the cmds array assignment ending with }; raw = ARGF.read.split( /cmds\[\] =\s+{\s*/m ).last.split( /^};$/ ).first commands = {} # break code into lines raw.split( /\n+/ ).each{ |line| line.gsub!( /(^\s*{\s*|\s*},?\*$)/, '' ) # discard wrapping for array elements mod = (line.scan( /^alt|^ctrl/ ).first || 'none').to_sym key = line.scan(/(?:^Key::(\w+)|(?.*?)(?