I know you can edit the bash prompt permanently by editing the PS1 variable in your ~/.bashrc file, mine looks like this:
PS1="\[\e[0;31m\]<HERP(._.)DERP>\[\e[0;0m\]";
but can you set a tiny little image in there as well? For instance, if I wanted to add a little American flag icon, or something before "HERP(._.)DERP", could I do this?
Actually, Yes, you can.
In recent versions of Bash, at least 4 (i could do it in 4.2 and 4.3), you can render emoji with the hex.
Use the echo -e
flag.
paste an emoji you looked up in and do a hexdump to see what it's made of:
plasmarob ~ $ echo -n "🇺🇸"| hexdump
0000000 f0 9f 87 ba f0 9f 87 b8
0000008
And then take that top line and escape each hex pair with \x :
plasmarob ~ $ echo -e 'See? \xf0\x9f\x87\xba\xf0\x9f\x87\xb8'
See? 🇺🇸
I actually modified mine to be:
plasmarob ~ âš¡
So yes, come up with one like this and try adding it to your .bashrc
or .bash_profile
.
Edit: Something with SO or browser rendering may have changed because the flag in this post now renders as a "US" character. YMMV but i assume it will still work in the stated versions of bash.
Nowadays, you can add emoji if you have an emoji-aware font. I guess this wasn't a easily viable option when the question was originally posted
I wrote this blog post about it a couple of years ago.
I don't know about American flags, but export PS1="\360\237\232\251 > "
gets a flag in your prompt.
I also wrote a shell tool to make printing the escapes for echo or shell prompt a little easier. It's called emo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With