Created
May 12, 2021 21:38
-
-
Save capezotte/a9cdf25133fbabfe7760253e5278585c to your computer and use it in GitHub Desktop.
Text-to-Emoji gawk script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/gawk -f | |
# GAWK because unicode | |
# Keycap boilerplate | |
function keycap(k) { return sprintf("%c%c%c",k "",65039,8419); } | |
BEGIN { | |
# Regex of included characters | |
unmatch="[^-[:blank]" | |
# A-Z (regional indicators are also a continuous range) | |
for (i=65;i<=90;i++) { regional[sprintf("%c",i)] = sprintf("%c",i+127397); } | |
# Keycaps | |
for (i=1;i<=9;i++) { regional[i] = keycap(i) } | |
regional["#"] = keycap("#"); regional["*"] = keycap("*") | |
# Punctuation marks | |
regional["?"] = "❔"; regional["!"] = "❕"; regional["."] = "▪️"; regional[","] = "🌙" | |
regional["+"] = "➕" # Minus can't be here because regex | |
# Quotes | |
regional["\""] = "⏸️"; regional["'"] = "🚦" | |
# Misc | |
regional["$"] = "💲"; regional["÷"] = "➗"; regional["~"] = "〰️"; regional["|"] = "🚦" | |
# Add all regional characters so far | |
for (char in regional) { | |
unmatch=unmatch char | |
} | |
# Dash - must be last because regex | |
regional["-"] = "➖" | |
# Anti-diacritic command | |
iconv="iconv -f utf8 -t ascii//TRANSLIT" | |
# Close regex | |
unmatch = "]" | |
} | |
{ | |
# Remove diacritrics | |
print $0 |& iconv | |
} | |
END { | |
# Iconv won't let us get the data until we close the pipe | |
close(iconv, "to") | |
# Get the data, now! | |
while (iconv |& getline) { | |
# Only uppercase | |
$0 = toupper($0) | |
# Remove | |
gsub(unmatch,"") | |
out="" | |
char_quant = split($0,chars,"") | |
for (i=1;i<=char_quant;i++) { | |
chr = chars[i] | |
if (regional[chr]) { | |
# Letter and digit | |
out = out " " regional[chr] | |
} else { | |
# Blank | |
out = out " " | |
} | |
} | |
print out | "xclip" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment