Fun with Shell Emojis
This article is nothing technical. I want to show the fun side of shell development.
Your shell environment doesn't need to be boring. We can decorate the shell's user messages with fun emojis that are random each time. It's a small touch that helps break the monotony of everyday terminal work.
Let me walk you through how to set this up on Linux, macOS, and Windows.
Linux (Debian/Ubuntu)
Shell environment: Bash
Add the following function to your ~/.bashrc:
rand_emoji() {
local imgs=("😊" "👻" "😽" "😺" "😌" "🙃" "😃" "🎂" "😎" "🤗" "😈" "🤡" "😻" "💩" "🤓" "🥳" "🤩" "🤑" "🙀" "😱" "🙈" "🧙" "🦄" "🧚" "🤖" "🐶" "🥂" "🍭" "🍿" "🎉" "🎊" "🕺" "🏮" "🎏" "🪔" "🔮" "🏆")
# Bash arrays are 0-based by default.
# $RANDOM % length returns a number from 0 to length-1.
local img_id=$(( RANDOM % ${#imgs[@]} ))
echo "${imgs[$img_id]:-🙂}"
}
How it works
local imgs=(...)— Declares a local array of emoji strings. Usinglocalkeeps the variable scoped to the function so it doesn't leak into your shell session.${#imgs[@]}— Returns the total number of elements in the array.$RANDOM— A built-in Bash variable that produces a random integer between 0 and 32767 each time it's referenced.$(( RANDOM % ${#imgs[@]} ))— The modulo (%) operation constrains the random number to a valid array index (0 to length-1), since Bash arrays are zero-based.${imgs[$img_id]:-🙂}— Looks up the emoji at the random index. The:-syntax is a fallback — if the value is empty or unset for any reason, it defaults to 🙂.
macOS
Shell environment: Zsh
Add the following function to your ~/.zshrc:
rand_emoji() {
local imgs=("😊" "👻" "😽" "😺" "😌" "🙃" "😃" "🎂" "😎" "🤗" "😈" "🤡" "😻" "💩" "🤓" "🥳" "🤩" "🤑" "🙀" "😱" "🙈" "🧙" "🦄" "🧚" "🤖" "🐶" "🥂" "🍭" "🍿" "🎉" "🎊" "🕺" "🏮" "🎏" "🪔" "🔮" "🏆")
# Zsh arrays are 1-based.
# We add +1 so the range becomes 1 to Length (instead of 0 to Length-1)
local img_id=$(( ($RANDOM % ${#imgs[@]}) + 1 ))
echo "${imgs[$img_id]:-🙂}"
}
How it works
local imgs=(...)— Same as Bash, declares a local array of emojis.${#imgs[@]}— Returns the array length, just like in Bash.$RANDOM— Works the same way as in Bash, producing a random integer.$(( ($RANDOM % ${#imgs[@]}) + 1 ))— This is where Zsh differs. Zsh arrays are 1-based (the first element is at index 1, not 0). The modulo gives us 0 to length-1, so we add 1 to shift the range to 1 through length — matching Zsh's indexing.${imgs[$img_id]:-🙂}— Looks up the emoji at the random index. The :- syntax is a fallback — if the value is empty or unset for any reason, it defaults to 🙂.
Windows
Shell environment: PowerShell
Add the following function to your PowerShell profile ($PROFILE):
function rand_emoji {
$emojis = @('😊', '👻', '😽', '😺', '😌', '🙃', '😃', '🎂', '😎', '🤗', '😈', '🤡', '😻', '💩', '🤓', '🥳', '🤩', '🤑', '🙀', '😱', '🙈', '🧙', '🦄', '🧚', '🤖', '🐶', '🥂', '🍭', '🍿', '🎉', '🎊', '🕺', '🏮', '🎏', '🪔', '🔮', '🏆')
return $emojis[(Get-Random -Minimum 0 -Maximum $emojis.Count)]
}
How it works
$emojis = @(...)— Creates a PowerShell array of emoji strings. The@()syntax explicitly defines an array. Unlike Bash/Zsh, PowerShell variables declared inside a function are local by default — nolocalkeyword needed.$emojis.Count— Returns the number of elements in the array. PowerShell arrays are zero-based, like Bash.Get-Random -Minimum 0 -Maximum $emojis.Count— PowerShell's built-in cmdlet for generating random numbers. The-Minimumis inclusive and-Maximumis exclusive, so this produces a value from 0 to length-1 — exactly what we need for a zero-based index.$emojis[...]— Standard array indexing to retrieve the emoji at the random position.
Try it out
Once you've added the function to your shell config, reload it (or open a new terminal) and run:
echo "Hi $(rand_emoji)"
Each time you run it, you'll get a different greeting — Hi 🦄, Hi 💩, Hi 🙃, and so on.
What can you do with this?
Here are a few ways to put rand_emoji to use:
- Customize your shell prompt — Prepend a random emoji to your prompt string (
PS1in Bash/Zsh,promptfunction in PowerShell) so every new command line feels a little different. - Liven up script output — Sprinkle
rand_emojiinto your build scripts, deployment tools, or CI logs to make status messages more glanceable and less wall-of-text. - Git commit hooks — Add an emoji to your pre-commit or post-commit messages for a quick visual cue in your log history.
Why bother?
- It reduces monotony — Staring at a plain terminal all day gets old. A small, random visual change keeps things just interesting enough to stay engaged.
- It's a low-effort morale boost — It takes two minutes to set up and costs nothing. A tiny 💩 or 🦄 popping up in your prompt can genuinely make you smile mid-debugging-session.
- It's a gateway to shell customization — Once you start tweaking your shell config for fun, you'll naturally learn more about how your environment works — arrays, variables, random numbers, profile scripts — all useful knowledge.
Make your shell environment more fun -- Try it!