Skip to content

Instantly share code, notes, and snippets.

@krowe
Last active August 29, 2015 14:10
Show Gist options
  • Save krowe/6bc8617638e242400dae to your computer and use it in GitHub Desktop.
Save krowe/6bc8617638e242400dae to your computer and use it in GitHub Desktop.
This bash script is similar to the cat GNU tool but it will interpret escape codes as it prints. This allows for you to use bash escape codes to make rich text files.
#!/bin/bash
while read -r; do
printf "%b\n" "$REPLY"
done < $1
printf "\e[0m"
\e[38;5;5;4;1mWhat is a BET file?\e[0m
A BET text file is much like an ordinary text file except that it may contain
bash escape codes. These codes allow for various formatting options when output
to a bash terminal or viewed from a viewer application. It isn't nearly as nice
to look at in raw form as a markdown file but because it can be displayed,
formatted, directly in your terminal that isn't going to be a big issue for
people who just want to read your files. When you write them you'll probably
want to use a purpose built editor anyway.
\e[38;5;3;4mSome Sample Formatting\e[0m
\e[38;5;5m pink\t\t\e[38;5;78mTeal
\e[38;5;15m white
\e[1m\e[38;5;46m bold green\e[0m
\e[38;5;46m green
\e[38;5;21m blue
\e[38;5;3m yellow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment