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

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

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

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:

Why bother?

Make your shell environment more fun -- Try it!