Skip to content

Commit

Permalink
🐛 Fix bash version check (#51)
Browse files Browse the repository at this point in the history
The bash version check was performed before declaring the
emoji array, so an error message was displayed by bash
before printing the custom error message. I also changed
the exit code to 1 (error) in the case of an old bash version.
  • Loading branch information
louib authored Jul 28, 2020
1 parent 2bd4a66 commit 6dc2c1d
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions emojify
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@

emojify_version=2.1.0

version_error_message="Oh my! That’s a very old version of bash you’re using, we don’t support that anymore :(
Consider upgrading it or, if you must use bash ${BASH_VERSION}, download an old version of
emojify from here: https://github.com/mrowa44/emojify/blob/old_bash_support/emojify"
# Checks the installed bash version to see if it's compatible with emojify
if (( ${BASH_VERSION%%.*} < 4 )); then
echo -e "$version_error_message"
exit 1
fi

# List generated by
# https://gist.github.com/GrenderG/fd4eb4c73eadad219b0ecb5f9345070a#file-emoji_scrap-py
# and emoji_scrap_github.py
Expand Down Expand Up @@ -2860,18 +2869,6 @@ EOF
exit 0
}

# Checks the installed bash version to see if it's compatible with emojify
check_version () {
if (( ${BASH_VERSION%%.*} >= 4 )); then
return
else
echo -e "Oh my! That’s a very old version of bash you’re using, we don’t support that anymore :(\n" \
"\nConsider upgrading it or, if you must use bash ${BASH_VERSION} download an old version of" \
"emojify from here: https://github.com/mrowa44/emojify/blob/old_bash_support/emojify"
exit 0
fi
}

# If arguments are provided on the command line then check for supported help
# options or process the arguments as emoji names.
if [[ -n $1 ]]; then
Expand All @@ -2889,12 +2886,10 @@ if [[ -n $1 ]]; then
;;

* )
check_version
emojify_line "$*"
;;
esac
else
check_version
while IFS=''; read -r line || [ -n "$line" ]; do
emojify_line "$line"
done
Expand Down

0 comments on commit 6dc2c1d

Please sign in to comment.