#!/usr/bin/env bash
set -euo pipefail

# Script Name: emoji
# Description: Interactive emoji picker with fuzzy search
# Source: Inspired by https://evanhahn.com/scripts-i-wrote-that-i-use-all-the-time/
# Usage: emoji           # interactive picker
#        emoji smile     # search for "smile"

# Curated emoji database (emoji + keywords)
emojis="😀 grinning face grin happy smile teeth cheerful
😃 smiley smile happy face open mouth teeth yay
😄 smile happy face grin laugh grinning eyes closed
😁 beaming smile happy grin teeth eyes closed
😆 laughing haha hahaha lol rofl laugh grinning squinting
😅 grinning sweat relief phew close call nervous laugh
🤣 rolling floor rofl laugh crying funny hilarious
😂 tears joy laugh cry funny lol crying
🙂 slightly smiling smile happy nice
🙃 upside down smile sarcastic silly
😉 wink flirt winky playful tease
😊 smiling eyes smile happy blush shy
😇 smiling halo angel innocent saint good
🥰 smiling hearts love adore crush hearts eyes
😍 heart eyes love crush hearts smiling loving
🤩 star eyes starstruck excited wow amazed
😘 blowing kiss love smooch mwah
😗 kissing smile kiss puckered
☺️ smiling face blushing happy relaxed
😚 kissing closed eyes kiss affection
😙 kissing smiling eyes kiss happy
🥲 smiling tear touched grateful sad happy bittersweet
😋 yummy delicious tasty savoring food yum
😛 tongue playful silly teasing
😜 winking tongue playful teasing kidding
🤪 zany crazy wild silly wacky goofy
😝 squinting tongue playful teasing horrible taste
🤑 money mouth dollar rich greedy cash
🤗 hugging hug embrace care support
🤭 hand mouth oops giggle secret tee hee
🫢 eyes hand peeking surprised shocked
🫣 peeking through fingers scared peek boo hide
🤫 shushing shh quiet secret silence hush
🤔 thinking hmm wonder ponder contemplative
🫡 salute respect military yes sir
🤐 zipper mouth secret sealed silent quiet
🤨 raised eyebrow skeptical suspicious doubt questioning
😐 neutral face blank expressionless meh
😑 expressionless annoyed blank dead inside
😶 no mouth quiet silent speechless
🫥 dotted line invisible disappearing transparent
😶‍🌫️ face clouds confused foggy unclear
😏 smirking smirk sly confident knowing
😒 unamused annoyed unimpressed disappointed meh
🙄 rolling eyes annoyed duh whatever sarcastic
😬 grimacing awkward uncomfortable eek cringe teeth
😮‍💨 exhaling sigh relief phew tired
🤥 lying pinocchio lie nose growing
🫨 shaking vibrating earthquake scared nervous
😌 relieved calm peaceful content relaxed
😔 pensive sad disappointed dejected down
😪 sleepy tired yawn exhausted drowsy
🤤 drooling hungry desire want covet
😴 sleeping sleep zzz asleep tired snooze
😷 face mask sick ill medical doctor protection
🤒 thermometer sick ill fever temperature
🤕 head bandage hurt injured wounded ow
🤢 nauseated sick queasy gross disgusted
🤮 vomiting puke sick throw up barf
🤧 sneezing gesundheit achoo sick cold allergies
🥵 hot face heat sweating fever burning
🥶 cold face freezing frozen ice chilly
🥴 woozy dizzy drunk tipsy disoriented confused
😵 dizzy face knocked out stunned shocked
😵‍💫 spiral eyes dizzy hypnotized dazed confused
🤯 exploding head mind blown shocked amazed
🤠 cowboy hat yee haw western
🥳 party celebrating birthday festive celebration confetti
🥸 disguise glasses nose mustache incognito spy
😎 sunglasses cool awesome rad shades
🤓 nerd geek smart glasses studious
🧐 monocle fancy classy rich thinking posh
😕 confused puzzled uncertain huh what
🫤 diagonal mouth meh unsure uncertain
😟 worried anxious concerned nervous afraid
🙁 slightly frowning sad disappointed unhappy
☹️ frowning sad upset disappointed down
😮 open mouth shocked surprised wow oh
😯 hushed surprised quiet wow shocked
😲 astonished shocked amazed surprised stunned gasping
😳 flushed embarrassed shy blush awkward
🥺 pleading puppy eyes begging please sad mercy
🥹 holding tears grateful touched emotional moved
😦 frowning open mouth shocked worried concerned
😧 anguished distressed worried scared oh no
😨 fearful scared afraid anxious fear
😰 anxious sweat nervous worried stressed cold sweat
😥 sad relieved phew sweat disappointed but relieved
😢 crying sad tear upset depressed
😭 loudly crying sobbing bawling devastated
😱 screaming fear shocked scared horrified scream
😖 confounded frustrated scrunched upset confused
😣 persevering struggling persevere powering through
😞 disappointed sad unhappy let down dejected
😓 downcast sweat sad worried stressed defeated
😩 weary exhausted tired fed up frustrated
😫 tired exhausted fed up frustrated stressed
🥱 yawning tired bored sleepy boring exhausted
😤 triumph victory proud won huffing
😡 angry mad furious enraged pouting
😠 angry mad annoyed frustrated upset
🤬 cursing swearing profanity symbols angry fuck
😈 smiling horns devil mischievous naughty evil
👿 angry horns devil mad evil angry purple
💀 skull dead death dying funny died
☠️ skull crossbones poison danger pirate deadly
💩 pile poo poop shit turd crap
🤡 clown joker funny creepy circus
👹 ogre monster oni demon red scary
👺 goblin monster oni demon tengu red nose
👻 ghost boo spooky halloween phantom
👽 alien extraterrestrial et space ufo
👾 alien monster space invader video game retro
🤖 robot bot ai machine automation
😺 grinning cat happy cat smiling feline
😸 grinning cat smiling eyes happy feline
😹 cat tears joy laughing funny cat
😻 cat heart eyes love smiling adore
😼 cat wry smile smirking sly cat
😽 kissing cat love kiss affection
🙀 weary cat surprised shocked scared screaming
😿 crying cat sad tear upset
😾 pouting cat angry grumpy annoyed mad
🙈 see no evil monkey blind ignore cover eyes
🙉 hear no evil monkey deaf ignore cover ears
🙊 speak no evil monkey silence quiet shh cover mouth
💋 kiss lips kissing love smooch
💌 love letter heart mail valentine romance
💘 heart arrow cupid love valentine romance
💝 heart ribbon gift present love valentine
💖 sparkling heart love sparkle shine
💗 growing heart love expanding bigger
💓 beating heart love heartbeat pulse
💞 revolving hearts love two hearts circling
💕 two hearts love romance pair couple
💟 heart decoration love ornament purple white
❣️ heart exclamation love emphasis
💔 broken heart heartbreak sad breakup hurt
❤️‍🔥 heart fire burning love passion flames
❤️‍🩹 mending heart healing recovery bandaged
❤️ red heart love valentine romance classic
🩷 pink heart love soft cute gentle
🧡 orange heart love friendship care
💛 yellow heart love happiness friendship
💚 green heart love nature jealous
💙 blue heart love trust calm loyal
🩵 light blue heart love peace calm soft
💜 purple heart love compassion sensitivity
🤎 brown heart love earth natural
🖤 black heart dark sad evil goth
🩶 grey heart love neutral indifferent
🤍 white heart love pure clean innocent
💯 hundred perfect 100 score full keep it 💯
💢 anger symbol mad angry frustrated
💥 collision bang boom crash pow explosion
💫 dizzy stars sparkles dazed seeing stars
💦 sweat droplets water splash wet
💨 dashing dash wind fast smoke puff gone
🕳️ hole pit gap void empty opening
💬 speech balloon talk chat speaking
👁️‍🗨️ eye speech bubble witness i see attention
🗨️ left speech bubble chat talk dialog
🗯️ right anger bubble mad shout yell
💭 thought balloon thinking wondering daydream
💤 zzz sleeping sleep snore tired
👋 waving hand hi hello goodbye wave bye
🤚 raised back hand stop wait hold on
🖐️ hand fingers splayed five stop high five
✋ raised hand stop halt wait high five
🖖 vulcan salute spock star trek live long prosper
🫱 rightwards hand pointing right offer
🫲 leftwards hand pointing left offer
🫳 palm down hand drop dismiss
🫴 palm up hand offering receive give
🫷 leftwards pushing hand stop reject push
🫸 rightwards pushing hand stop reject push
👌 ok hand okay perfect good chef kiss
🤌 pinched fingers italian gesture what
🤏 pinching hand tiny small little bit
✌️ victory hand peace sign v two
🤞 crossed fingers luck wish hope good luck
🫰 hand index thumb snap click money pay
🤟 love you hand sign i love you
🤘 sign horns rock metal devil horns
🤙 call me hand phone shaka hang loose
👈 backhand index pointing left left that
👉 backhand index pointing right right that
👆 backhand index pointing up up above that
🖕 middle finger fuck you rude profanity flip off
👇 backhand index pointing down down below that
☝️ index pointing up one attention above
🫵 index pointing you your attention
👍 thumbs up good yes like approve agree
👎 thumbs down bad no dislike disapprove disagree
✊ raised fist power solidarity resistance punch
👊 oncoming fist punch bump fist bump bro
🤛 left facing fist punch bump fist bump
🤜 right facing fist punch bump fist bump
👏 clapping hands applause clap bravo good job
🙌 raising hands celebration praise yay hooray hallelujah
🫶 heart hands love support care fingers
👐 open hands hug embrace jazz hands
🤲 palms together pray please namaste dua
🤝 handshake deal agreement hello meeting shake
🙏 folded hands pray thank you please thanks namaste
✍️ writing hand writing write author pen
💅 nail polish nails beauty makeup manicure slay
🤳 selfie camera photo picture self portrait
💪 flexed biceps strong muscle strength flex gym
🦾 mechanical arm prosthetic cyborg robot strong
🦿 mechanical leg prosthetic cyborg robot
🦵 leg kick limb
🦶 foot step kick toe
👂 ear hearing listen sound
🦻 ear hearing aid deaf listen
👃 nose smell sniff scent
🧠 brain smart intelligent think mind
🫀 anatomical heart real heart organ medical
🫁 lungs breathing respiratory organ medical
🦷 tooth teeth dentist dental smile
🦴 bone skeleton fossil
👀 eyes looking watching see stare observe
👁️ eye looking watching see vision
👅 tongue lick taste silly
👄 mouth lips kiss kissing speaking
🫦 biting lip nervous anxious flirting
👶 baby infant newborn child young
🧒 child kid young boy girl
👦 boy child kid young male
👧 girl child kid young female
🧑 person human adult gender neutral
👱 blond person blonde hair fair
👨 man male adult guy dude gentleman
🧔 bearded person beard facial hair
🧔‍♂️ man beard facial hair
🧔‍♀️ woman beard facial hair
👨‍🦰 man red hair ginger
👨‍🦱 man curly hair
👨‍🦳 man white hair old elderly
👨‍🦲 man bald no hair
👩 woman female adult lady
👩‍🦰 woman red hair ginger
👩‍🦱 woman curly hair
👩‍🦳 woman white hair old elderly
👩‍🦲 woman bald no hair
🧓 older adult elderly senior old
👴 old man elderly grandfather senior
👵 old woman elderly grandmother senior
🙍 person frowning sad upset disappointed
🙍‍♂️ man frowning sad upset
🙍‍♀️ woman frowning sad upset
🙎 person pouting angry mad annoyed
🙎‍♂️ man pouting angry mad
🙎‍♀️ woman pouting angry mad
🙅 person gesturing no nope stop
🙅‍♂️ man gesturing no nope stop
🙅‍♀️ woman gesturing no nope stop
🙆 person gesturing ok okay yes
🙆‍♂️ man gesturing ok okay yes
🙆‍♀️ woman gesturing ok okay yes
💁 person tipping hand information sass
💁‍♂️ man tipping hand information
💁‍♀️ woman tipping hand information sass
🙋 person raising hand question attention pick me
🙋‍♂️ man raising hand question
🙋‍♀️ woman raising hand question
🧏 deaf person sign language deaf
🧏‍♂️ deaf man sign language
🧏‍♀️ deaf woman sign language
🙇 person bowing sorry thank you respect
🙇‍♂️ man bowing sorry respect
🙇‍♀️ woman bowing sorry respect
🤦 person facepalming facepalm frustrated duh disappointed
🤦‍♂️ man facepalming facepalm frustrated
🤦‍♀️ woman facepalming facepalm frustrated
🤷 person shrugging idk dunno shrug don't know whatever
🤷‍♂️ man shrugging idk dunno
🤷‍♀️ woman shrugging idk dunno
🧑‍⚕️ health worker doctor nurse medical
👨‍⚕️ man health worker doctor
👩‍⚕️ woman health worker doctor nurse
🧑‍🎓 student school college university
👨‍🎓 man student graduate
👩‍🎓 woman student graduate
🧑‍🏫 teacher professor educator
👨‍🏫 man teacher professor
👩‍🏫 woman teacher professor
🧑‍⚖️ judge law legal court justice
👨‍⚖️ man judge law
👩‍⚖️ woman judge law
🧑‍🌾 farmer agriculture crops
👨‍🌾 man farmer agriculture
👩‍🌾 woman farmer agriculture
🧑‍🍳 cook chef cooking
👨‍🍳 man cook chef
👩‍🍳 woman cook chef
🧑‍🔧 mechanic technician repair
👨‍🔧 man mechanic technician
👩‍🔧 woman mechanic technician
🧑‍🏭 factory worker industrial
👨‍🏭 man factory worker
👩‍🏭 woman factory worker
🧑‍💼 office worker business professional
👨‍💼 man office worker business
👩‍💼 woman office worker business
🧑‍🔬 scientist research lab
👨‍🔬 man scientist research
👩‍🔬 woman scientist research
🧑‍💻 technologist developer programmer coder hacker computer
👨‍💻 man technologist developer programmer
👩‍💻 woman technologist developer programmer
🧑‍🎤 singer performer music artist
👨‍🎤 man singer rockstar
👩‍🎤 woman singer rockstar
🧑‍🎨 artist painter creative
👨‍🎨 man artist painter
👩‍🎨 woman artist painter
🧑‍✈️ pilot aviation plane flight
👨‍✈️ man pilot aviation
👩‍✈️ woman pilot aviation
🧑‍🚀 astronaut space cosmonaut
👨‍🚀 man astronaut space
👩‍🚀 woman astronaut space
🧑‍🚒 firefighter fire emergency
👨‍🚒 man firefighter fire
👩‍🚒 woman firefighter fire
👮 police officer cop law enforcement
👮‍♂️ man police officer cop
👮‍♀️ woman police officer cop
🕵️ detective spy investigator sleuth
🕵️‍♂️ man detective spy
🕵️‍♀️ woman detective spy
💂 guard soldier royal british
💂‍♂️ man guard soldier
💂‍♀️ woman guard soldier
🥷 ninja stealth assassin martial arts
👷 construction worker builder hard hat
👷‍♂️ man construction worker builder
👷‍♀️ woman construction worker builder
🫅 person crown royalty monarch king queen
🤴 prince royalty nobility fairy tale
👸 princess royalty nobility fairy tale
👳 person turban wearing turban
👳‍♂️ man turban wearing
👳‍♀️ woman turban wearing
👲 person skullcap cap hat chinese
🧕 woman headscarf hijab muslim
🤵 person tuxedo formal wedding groom
🤵‍♂️ man tuxedo formal groom
🤵‍♀️ woman tuxedo formal
👰 person veil wedding bride marriage
👰‍♂️ man veil wedding groom
👰‍♀️ woman veil wedding bride
🤰 pregnant woman expecting baby
🫃 pregnant man trans expecting
🫄 pregnant person expecting baby
👼 baby angel cherub halo innocent
🎅 santa claus christmas saint nick father christmas
🤶 mrs claus christmas mother
🧑‍🎄 mx claus christmas gender neutral
🦸 superhero hero power super cape
🦸‍♂️ man superhero hero
🦸‍♀️ woman superhero hero
🦹 supervillain villain evil bad
🦹‍♂️ man supervillain villain
🦹‍♀️ woman supervillain villain
🧙 mage wizard witch magic sorcerer
🧙‍♂️ man mage wizard sorcerer
🧙‍♀️ woman mage witch sorceress
🧚 fairy magic pixie sprite wings
🧚‍♂️ man fairy magic
🧚‍♀️ woman fairy magic pixie
🧛 vampire dracula undead fangs blood
🧛‍♂️ man vampire dracula
🧛‍♀️ woman vampire dracula
🧜 merperson mermaid merman ocean sea
🧜‍♂️ merman triton ocean
🧜‍♀️ mermaid ariel ocean
🧝 elf fantasy magic legolas
🧝‍♂️ man elf fantasy
🧝‍♀️ woman elf fantasy
🧞 genie magic wish lamp djinn
🧞‍♂️ man genie magic
🧞‍♀️ woman genie magic
🧟 zombie undead walker brain dead
🧟‍♂️ man zombie undead
🧟‍♀️ woman zombie undead
🧌 troll internet monster ugly
💆 person getting massage spa relaxation
💆‍♂️ man getting massage spa
💆‍♀️ woman getting massage spa
💇 person getting haircut salon barber
💇‍♂️ man getting haircut barber
💇‍♀️ woman getting haircut salon
🚶 person walking walk stroll
🚶‍♂️ man walking walk
🚶‍♀️ woman walking walk
🧍 person standing stand up
🧍‍♂️ man standing stand
🧍‍♀️ woman standing stand
🧎 person kneeling kneel pray
🧎‍♂️ man kneeling kneel
🧎‍♀️ woman kneeling kneel
🧑‍🦯 person white cane blind visually impaired
👨‍🦯 man white cane blind
👩‍🦯 woman white cane blind
🧑‍🦼 person motorized wheelchair disabled
👨‍🦼 man motorized wheelchair disabled
👩‍🦼 woman motorized wheelchair disabled
🧑‍🦽 person manual wheelchair disabled
👨‍🦽 man manual wheelchair disabled
👩‍🦽 woman manual wheelchair disabled
🏃 person running run jog exercise sprint
🏃‍♂️ man running run jog
🏃‍♀️ woman running run jog
💃 woman dancing dance party salsa
🕺 man dancing dance party disco
🕴️ person suit levitating floating hovering
👯 people bunny ears party dancers
👯‍♂️ men bunny ears party
👯‍♀️ women bunny ears party
🧖 person steamy room sauna spa steam
🧖‍♂️ man steamy room sauna
🧖‍♀️ woman steamy room sauna
🧗 person climbing climb rock climbing
🧗‍♂️ man climbing climb
🧗‍♀️ woman climbing climb
🤺 person fencing sword sport
🏇 horse racing jockey racing equestrian
⛷️ skier skiing snow winter sport
🏂 snowboarder snowboarding snow winter
🏌️ person golfing golf sport
🏌️‍♂️ man golfing golf
🏌️‍♀️ woman golfing golf
🏄 person surfing surf wave beach
🏄‍♂️ man surfing surf wave
🏄‍♀️ woman surfing surf wave
🚣 person rowing boat row water
🚣‍♂️ man rowing boat row
🚣‍♀️ woman rowing boat row
🏊 person swimming swim pool water
🏊‍♂️ man swimming swim
🏊‍♀️ woman swimming swim
⛹️ person bouncing ball basketball sport
⛹️‍♂️ man bouncing ball basketball
⛹️‍♀️ woman bouncing ball basketball
🏋️ person lifting weights gym workout exercise
🏋️‍♂️ man lifting weights gym
🏋️‍♀️ woman lifting weights gym
🚴 person biking bike bicycle cycling
🚴‍♂️ man biking bike bicycle
🚴‍♀️ woman biking bike bicycle
🚵 person mountain biking bike trail
🚵‍♂️ man mountain biking bike
🚵‍♀️ woman mountain biking bike
🤸 person cartwheeling gymnastics cartwheel
🤸‍♂️ man cartwheeling gymnastics
🤸‍♀️ woman cartwheeling gymnastics
🤼 people wrestling wrestle sport
🤼‍♂️ men wrestling wrestle
🤼‍♀️ women wrestling wrestle
🤽 person playing water polo water sport
🤽‍♂️ man playing water polo
🤽‍♀️ woman playing water polo
🤾 person playing handball handball sport
🤾‍♂️ man playing handball
🤾‍♀️ woman playing handball
🤹 person juggling juggle circus performance
🤹‍♂️ man juggling juggle
🤹‍♀️ woman juggling juggle
🧘 person lotus position yoga meditation zen
🧘‍♂️ man lotus position yoga
🧘‍♀️ woman lotus position yoga
🛀 person taking bath bathtub shower relaxing
🛌 person bed sleeping rest sleep
🧑‍🤝‍🧑 people holding hands friends together couple
👭 women holding hands friends together couple
👫 woman man holding hands couple together
👬 men holding hands friends together couple
💏 kiss couple love romance kissing
👩‍❤️‍💋‍👨 kiss woman man couple love
👨‍❤️‍💋‍👨 kiss man man couple love gay
👩‍❤️‍💋‍👩 kiss woman woman couple love lesbian
💑 couple heart love together romance
👩‍❤️‍👨 couple heart woman man love
👨‍❤️‍👨 couple heart man man love gay
👩‍❤️‍👩 couple heart woman woman love lesbian
👨‍👩‍👦 family man woman boy parents child
👨‍👩‍👧 family man woman girl parents child
👨‍👩‍👧‍👦 family man woman girl boy parents children
👨‍👩‍👦‍👦 family man woman boy boy parents children
👨‍👩‍👧‍👧 family man woman girl girl parents children
👨‍👨‍👦 family man man boy gay parents
👨‍👨‍👧 family man man girl gay parents
👨‍👨‍👧‍👦 family man man girl boy gay parents
👨‍👨‍👦‍👦 family man man boy boy gay parents
👨‍👨‍👧‍👧 family man man girl girl gay parents
👩‍👩‍👦 family woman woman boy lesbian parents
👩‍👩‍👧 family woman woman girl lesbian parents
👩‍👩‍👧‍👦 family woman woman girl boy lesbian parents
👩‍👩‍👦‍👦 family woman woman boy boy lesbian parents
👩‍👩‍👧‍👧 family woman woman girl girl lesbian parents
👨‍👦 family man boy father son parent
👨‍👦‍👦 family man boy boy father sons
👨‍👧 family man girl father daughter
👨‍👧‍👦 family man girl boy father children
👨‍👧‍👧 family man girl girl father daughters
👩‍👦 family woman boy mother son parent
👩‍👦‍👦 family woman boy boy mother sons
👩‍👧 family woman girl mother daughter
👩‍👧‍👦 family woman girl boy mother children
👩‍👧‍👧 family woman girl girl mother daughters
🗣️ speaking head talking voice sound speaking
👤 bust silhouette profile person user
👥 busts silhouette people users group crowd
🫂 people hugging hug embrace support comfort
👣 footprints feet steps walking tracks"

if command -v fzf &>/dev/null; then
  # Interactive mode with fzf
  if [[ $# -eq 0 ]]; then
    selected=$(echo "$emojis" | fzf --height=60% --layout=reverse \
      --prompt="Select emoji: " \
      --preview='echo {}' \
      --preview-window=up:1:wrap)
    if [[ -n "$selected" ]]; then
      emoji_char=$(echo "$selected" | awk '{print $1}')
      echo -n "$emoji_char" | pbcopy
      echo "Copied: $emoji_char"
    fi
  else
    # Search mode
    echo "$emojis" | grep -i "$@" | head -20
  fi
else
  # Fallback without fzf - just search
  if [[ $# -eq 0 ]]; then
    echo "$emojis"
  else
    echo "$emojis" | grep -i "$@"
  fi
fi
