Created
October 2, 2018 18:33
-
-
Save luanjunyi/66a3beeb4f35871c502107100668b540 to your computer and use it in GitHub Desktop.
Camel/Snake case convert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
name=$1 | |
if [[ "$name" =~ [A-Z] ]]; then | |
# convert camel case to snake case | |
echo $name | sed -r 's/([A-Z])/_\L\1/g' | sed 's/^_//g' | |
else | |
# convert snake case to camel case | |
echo $name | sed -r 's|_([a-z])|\U\1|g' | |
echo $name | sed -r 's|_([a-z])|\U\1|g' | sed 's|^\([a-z]\)|\u\1|' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment