Fun with Shell Emojis | Lasantha Kularatne



Lasantha Kularatne




posts

shell

terminal

bash

zsh

powershell

fun

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. Using local keeps 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 โ€” no local keyword 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 -Minimum is inclusive and -Maximum is 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 (PS1 in Bash/Zsh, prompt function in PowerShell) so every new command line feels a little different.
  • Liven up script output โ€” Sprinkle rand_emoji into 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!




Source link

Leave a Reply

Your email address will not be published. Required fields are marked *