From c3914e6cc437579ad867277670a590369cd75144 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 28 Jan 2024 00:43:09 -0300 Subject: [PATCH] Add bin/emit --- bin/emit | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 bin/emit diff --git a/bin/emit b/bin/emit new file mode 100755 index 0000000..817bd79 --- /dev/null +++ b/bin/emit @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby +$stdout.sync = true + +def noecho + system "stty -echo" + str = yield + system "stty echo" + str +end + +loop do + str = noecho { $stdin.gets } + str = str.gsub(/[^A-Za-z0-9_\s\/\-,;:"']/, '') + sep = "\t" + class_name, class_body = str.split(sep, 2) + if class_name && class_body + class_name.gsub!(%r|([/.])|) { "\\#{_1}" } + print ".#{class_name.chomp}", + " { \n", + " " * 2, + class_body.chomp, + "\n}\n" + end +end