#!/bin/env ruby
# convert a string into macro syntax for TMK firmware
# be sure to escape quotes e.g. ruby macro.rb "Pass\"word1"
# usage: ruby macro.rb "STRING"
# Example:
# prompt# ruby macro.rb "this\"is aPa33word"
# "T(T), T(H), T(I), T(S), D(LSFT), T(QUOT), U(LSFT), T(I), T(S), D(LSFT),/
# T(SPC), U(LSFT), T(A), D(LSFT), T(P), U(LSFT), T(A), T(3), T(3), T(W),/
# T(O), T(R), T(D), "
# only tested with this fork: https://github.com/cub-uanic/tmk_keyboard/tree/cub_layout
# using os x
shifted_special_chars = { "!" => "1", "@" => "2", "#" => "3", "$" => "4", "%" => "5", "^" => "6", "&" => "7", "*" => "8", "(" => "9", ")" => "0" , "~" => "GRV", "?" => "SLSH", "<" => "COMM", ">" => "DOT", "{" => "LBRC", "}" => "RBRC", "|" => "BSLS", '"' => "QUOT", " " => "SPC", ":" => "SCLN"}
unshifted_special_chars = { "`" => "GRV", "/" => "SLSH", "," => "COMM", ";" => "SCLN", "." => "DOT", "[" => "LBRC", "]" => "RBRC", "\\" => "BSLS", '"' => "QUOT" }
def type(char)
"T(#{char})"
end
def shift(char)
"D(LSFT), #{char}, U(LSFT)"
end
@mac = ""
ARGV[0].each_char do |char|
case
when char =~ /[A-Z]/
@mac << shift("#{type(char)}")
when char =~ /[a-z\d]/
@mac << type(char).upcase
when shifted_special_chars.has_key?(char)
char = shifted_special_chars[char]
@mac << shift("#{type(char)}")
when unshifted_special_chars.has_key?(char)
char = unshifted_special_chars[char]
@mac << type(char)
end
@mac << ", "
end
p @mac