How can Homebrew print a beer mug in Terminal?

77

25

Homebrew has a neat trick of printing out little icons next to its output. Like this:

brew icons in terminal output

If I copy paste the icon it on its own and hit enter I get the result:

-bash: $'?\237\215?': command not found

And if I try it with echo or printf I just get ????. Same if I escape all the quotes and $s etc.

editron:~ stib$ echo $'?\237\215?'
????

So how do they do that? What do the magic characters $'?\237\215?' mean?

stib

Posted 2013-01-18T04:54:46.533

Reputation: 3 320

Answers

68

Homebrew is open source, so you can read its code to find out how it shows the icon. The line they're using is in the file formula_installer.rb:

print "  " if MacOS.version >= :lion

The first character in the print command is a "", or unicode #1f37a 'BEER MUG'.

So it's not an icon but an funny unicode beer mug :)

zed_0xff

Posted 2013-01-18T04:54:46.533

Reputation: 820

1Also from just about anywhere in OS X you can summon the Emoji keyboard using the shortcut Ctrl + Cmd + Space. Doesn't work everywhere but works in most places – dominicbri7 – 2016-07-29T09:20:27.907

18Awesome. So in the shell I can just do echo -e "\xF0\x9f\x8d\xba" – stib – 2013-01-18T13:28:25.390

4Also, try looking it up in the OS X dictionary (right click > look up) ;) – ihatetoregister – 2013-02-13T01:13:37.233

4Or with octal: echo $'\360\237\215\272' – Chad Skeeters – 2013-07-03T21:46:02.420

13

BTW, try another variants in terminal:

echo $'\360\237\215\270'
echo $'\360\237\215\271'
echo $'\360\237\215\273'
echo $'\360\237\215\274'

Ivan

Posted 2013-01-18T04:54:46.533

Reputation: 231

3

For those who do not have a font containing these symbols: These are symbols/pictures of various drinks. See http://codepoints.net/miscellaneous_symbols_and_pictographs

– pabouk – 2013-11-04T05:50:51.657