Skip to content

Instantly share code, notes, and snippets.

@luanjunyi
Created October 2, 2018 18:33
Show Gist options
  • Save luanjunyi/66a3beeb4f35871c502107100668b540 to your computer and use it in GitHub Desktop.
Save luanjunyi/66a3beeb4f35871c502107100668b540 to your computer and use it in GitHub Desktop.
Camel/Snake case convert
#! /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