Skip to content

Instantly share code, notes, and snippets.

@pndurette
Last active March 3, 2021 21:16
Show Gist options
  • Save pndurette/67e204c0ee4ea2e1f28e839b059d36b2 to your computer and use it in GitHub Desktop.
Save pndurette/67e204c0ee4ea2e1f28e839b059d36b2 to your computer and use it in GitHub Desktop.
Cursed script to convert text to Slack's :alphabet-*: emoji
#!/bin/bash
# $0 <text to convert>
# COLOUR=yellow $0 <text to convert>
TEXT="$@"
COLOUR="${COLOUR:-white}" # can be 'yellow'
REGEX='^[a-zA-Z\!\?\#\@\ ]+$'
[[ $TEXT =~ $REGEX ]] || \
{ echo "Text must match $REGEX"; exit 1; }
echo "${TEXT}" | \
sed -r "s/([a-zA-Z])/:alphabet-${COLOUR}-\1:/g" | \
sed -r "s/(\!)/:alphabet-${COLOUR}-exclamation:/g" | \
sed -r "s/(\?)/:alphabet-${COLOUR}-question:/g" | \
sed -r "s/(\#)/:alphabet-${COLOUR}-hash:/g" | \
sed -r "s/(\@)/:alphabet-${COLOUR}-at:/g"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment