dotfiles/pty2tty.awk
Gabe Venberg 18cc077a9b Squashed 'zsh/.zsh/tty-solarized/' content from commit a435d9b
git-subtree-dir: zsh/.zsh/tty-solarized
git-subtree-split: a435d9b4f7aaa9e0dd0494c504fc1fe3c6a22eee
2018-08-06 17:43:12 -05:00

45 lines
1.2 KiB
Awk
Executable file

#!/usr/bin/gawk -f
# pty2tty.awk: Create solarized color scheme for TTY.
# Usage: ./pty2tty.awk [-v t=light|dark] $Xresources
# With $Xresources from http://github.com/altercation.
# Put resulting code in your shell's startup/login file.
# By Joep van Delft, 2013
BEGIN {
if (t~/^[lL]+/) theme="light"
else theme="dark"
}
/! (Common|Dark|Light) *$/ {
flag=tolower($2)
next
}
/^(! |)#define/ {
if (flag=="common" || flag==theme) {
solar[$(NF-1)]["var"] = gensub(/[^[:xdigit:]]/,"","g",$NF)
}
next
}
/^\*color/ {
solar[$2]["code"] = gensub(/[^[:digit:]]+/,"","g",$1)
next
}
END{
print "# Solarized theme for tty, the", theme, "version."
print "# Based on:"
print "# - Solarized (http://ethanschoonover.com/solarized)"
print "# - Xresources from http://github.com/altercation/solarized"
print "# Generated with pty2tty.awk by Joep van Delft"
print "# http://github.com/joepvd/tty-solarized"
print "if [ \"$TERM\" = \"linux\" ]; then"
for (desc in solar)
printf " echo -en \"\\e]P%X%s\" # %s\n", \
solar[desc]["code"], \
solar[desc]["var"], \
desc
print " clear # against bg artifacts\nfi"
}